blob: 9e6652301b8cd8d2f737f8adb48fcdb776629abd [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Paul Duffin036e7002019-12-19 19:16:28 +000036 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Paul Duffin036e7002019-12-19 19:16:28 +000038 pctx.Import("android/soong/cc/config")
39}
40
41func RegisterCCBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
43
44 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Crossc511bc52020-04-07 16:50:32 +000045 ctx.BottomUp("sdk", sdkMutator).Parallel()
Inseob Kim64c43952019-08-26 16:52:35 +090046 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070047 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090048 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010049 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090050 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070051 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090052 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090053 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
54 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070055 })
Colin Cross16b23492016-01-06 14:41:07 -080056
Paul Duffin036e7002019-12-19 19:16:28 +000057 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070058 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
59 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080060
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070061 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
62 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
63
Mitch Phillipsbfeade62019-05-01 14:42:05 -070064 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
65 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
66
Jiyong Park1d1119f2019-07-29 21:27:18 +090067 // cfi mutator shouldn't run before sanitizers that return true for
68 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000069 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
70 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
71
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080072 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
73 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
74
Colin Cross1e676be2016-10-12 14:38:15 -070075 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
76 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080077
Colin Cross0b908332019-06-19 23:00:20 -070078 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090079 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080080
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080081 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080082 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070083
84 ctx.TopDown("lto_deps", ltoDepsMutator)
85 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090086
87 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070088 })
Colin Crossb98c8b02016-07-29 13:44:28 -070089
Sasha Smundak2a4549e2018-11-05 16:49:08 -080090 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070091}
92
Colin Crossca860ac2016-01-04 14:34:37 -080093type Deps struct {
94 SharedLibs, LateSharedLibs []string
95 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080096 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080097 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070098
Chris Parsons79d66a52020-06-05 17:26:16 -040099 // Used for data dependencies adjacent to tests
100 DataLibs []string
101
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800102 StaticUnwinderIfLegacy bool
103
Colin Cross5950f382016-12-13 12:50:57 -0800104 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700105
Colin Cross81413472016-04-11 14:37:39 -0700106 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700107
Dan Willemsenb40aab62016-04-20 14:21:14 -0700108 GeneratedSources []string
109 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900110 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700111
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700112 ReexportGeneratedHeaders []string
113
Colin Cross97ba0732015-03-23 17:50:24 -0700114 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700115
116 // Used for host bionic
117 LinkerFlagsFile string
118 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700119}
120
Colin Crossca860ac2016-01-04 14:34:37 -0800121type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700122 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900123 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700124 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900125 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700126 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700127 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700128
Colin Cross26c34ed2016-09-30 17:10:16 -0700129 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100130 Objs Objects
131 // Paths to .o files in dependencies that provide them. Note that these lists
132 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800133 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700134 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700135
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100136 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
137 // the libs from all whole_static_lib dependencies.
138 WholeStaticLibsFromPrebuilts android.Paths
139
Colin Cross26c34ed2016-09-30 17:10:16 -0700140 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700141 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900142 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700143
Inseob Kimd110f872019-12-06 13:15:38 +0900144 Flags []string
145 IncludeDirs android.Paths
146 SystemIncludeDirs android.Paths
147 ReexportedDirs android.Paths
148 ReexportedSystemDirs android.Paths
149 ReexportedFlags []string
150 ReexportedGeneratedHeaders android.Paths
151 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700152
Colin Cross26c34ed2016-09-30 17:10:16 -0700153 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700154 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700155
156 // Path to the file container flags to use with the linker
157 LinkerFlagsFile android.OptionalPath
158
159 // Path to the dynamic linker binary
160 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700161}
162
Colin Cross4af21ed2019-11-04 09:37:55 -0800163// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
164// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
165// command line so they can be overridden by the local module flags).
166type LocalOrGlobalFlags struct {
167 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700168 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800169 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700170 CFlags []string // Flags that apply to C and C++ source files
171 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
172 ConlyFlags []string // Flags that apply to C source files
173 CppFlags []string // Flags that apply to C++ source files
174 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700175 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800176}
177
178type Flags struct {
179 Local LocalOrGlobalFlags
180 Global LocalOrGlobalFlags
181
182 aidlFlags []string // Flags that apply to aidl source files
183 rsFlags []string // Flags that apply to renderscript source files
184 libFlags []string // Flags to add libraries early to the link order
185 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
186 TidyFlags []string // Flags that apply to clang-tidy
187 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700188
Colin Crossc3199482017-03-30 15:03:04 -0700189 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800190 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700191 SystemIncludeFlags []string
192
Oliver Nguyen04526782020-04-21 12:40:27 -0700193 Toolchain config.Toolchain
194 Tidy bool
195 GcovCoverage bool
196 SAbiDump bool
197 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800198
199 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800200 DynamicLinker string
201
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700202 CFlagsDeps android.Paths // Files depended on by compiler flags
203 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800204
Dan Willemsen98ab3112019-08-27 21:20:40 -0700205 AssemblerWithCpp bool
206 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800207
Colin Cross19878da2019-03-28 14:45:07 -0700208 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700209 protoC bool // Whether to use C instead of C++
210 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700211
212 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700213}
214
Colin Crossca860ac2016-01-04 14:34:37 -0800215// Properties used to compile all C or C++ modules
216type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700217 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800218 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700219
Colin Crossc511bc52020-04-07 16:50:32 +0000220 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
221 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800222 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700223
Jooyung Han379660c2020-04-21 15:24:00 +0900224 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
225 Min_sdk_version *string
226
Colin Crossc511bc52020-04-07 16:50:32 +0000227 // If true, always create an sdk variant and don't create a platform variant.
228 Sdk_variant_only *bool
229
Jiyong Parkde866cb2018-12-07 23:08:36 +0900230 AndroidMkSharedLibs []string `blueprint:"mutated"`
231 AndroidMkStaticLibs []string `blueprint:"mutated"`
232 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
233 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700234 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900235 HideFromMake bool `blueprint:"mutated"`
236 PreventInstall bool `blueprint:"mutated"`
237 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700238
Justin Yun5f7f7e82019-11-18 19:52:14 +0900239 ImageVariationPrefix string `blueprint:"mutated"`
240 VndkVersion string `blueprint:"mutated"`
241 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800242
243 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
244 // file
245 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900246
Yifan Hong1b3348d2020-01-21 15:53:22 -0800247 // Make this module available when building for ramdisk
248 Ramdisk_available *bool
249
Jiyong Parkf9332f12018-02-01 00:54:12 +0900250 // Make this module available when building for recovery
251 Recovery_available *bool
252
Colin Crossae6c5202019-11-20 13:35:50 -0800253 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800254 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800255 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800256 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900257 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900258
259 // Allows this module to use non-APEX version of libraries. Useful
260 // for building binaries that are started before APEXes are activated.
261 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900262
263 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
264 // see soong/cc/config/vndk.go
265 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900266
267 // Used by vendor snapshot to record dependencies from snapshot modules.
268 SnapshotSharedLibs []string `blueprint:"mutated"`
269 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000270
271 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000272
273 // Set by factories of module types that can only be referenced from variants compiled against
274 // the SDK.
275 AlwaysSdk bool `blueprint:"mutated"`
276
277 // Variant is an SDK variant created by sdkMutator
278 IsSdkVariant bool `blueprint:"mutated"`
279 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
280 // variant to have a ".sdk" suffix.
281 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700282}
283
284type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900285 // whether this module should be allowed to be directly depended by other
286 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900287 // In addition, this module should be allowed to be directly depended by
288 // product modules with `product_specific: true`.
289 // If set to true, three variants will be built separately, one like
290 // normal, another limited to the set of libraries and headers
291 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700292 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900293 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700294 // so it shouldn't have any unversioned runtime dependencies, or
295 // make assumptions about the system that may not be true in the
296 // future.
297 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900298 // If set to false, this module becomes inaccessible from /vendor or /product
299 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900300 //
301 // Default value is true when vndk: {enabled: true} or vendor: true.
302 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700303 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900304 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700305 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900306
307 // whether this module is capable of being loaded with other instance
308 // (possibly an older version) of the same module in the same process.
309 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
310 // can be double loaded in a vendor process if the library is also a
311 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
312 // explicitly marked as `double_loadable: true` by the owner, or the dependency
313 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
314 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800315}
316
Colin Crossca860ac2016-01-04 14:34:37 -0800317type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800318 static() bool
319 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900320 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900321 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900322 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700323 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900324 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700325 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800326 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700327 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800328 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900329 isLlndk(config android.Config) bool
330 isLlndkPublic(config android.Config) bool
331 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900332 isVndk() bool
333 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800334 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900335 inProduct() bool
336 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800337 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900338 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800339 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700340 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700341 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800342 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800343 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800344 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800345 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800346 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900347 apexName() string
Jooyung Hanccce2f22020-03-07 03:45:53 +0900348 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900349 hasStubsVariants() bool
350 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900351 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800352 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700353 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800354}
355
356type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700357 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800358 ModuleContextIntf
359}
360
361type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700362 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800363 ModuleContextIntf
364}
365
Colin Cross37047f12016-12-13 17:06:13 -0800366type DepsContext interface {
367 android.BottomUpMutatorContext
368 ModuleContextIntf
369}
370
Colin Crossca860ac2016-01-04 14:34:37 -0800371type feature interface {
372 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800373 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800374 flags(ctx ModuleContext, flags Flags) Flags
375 props() []interface{}
376}
377
378type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700379 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800380 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800381 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700382 compilerProps() []interface{}
383
Colin Cross76fada02016-07-27 10:31:13 -0700384 appendCflags([]string)
385 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700386 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800387}
388
389type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700390 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800391 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700392 linkerFlags(ctx ModuleContext, flags Flags) Flags
393 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800394 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700395
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700396 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700397 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900398 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700399
400 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900401 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000402
403 // Get the deps that have been explicitly specified in the properties.
404 // Only updates the
405 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
406}
407
408type specifiedDeps struct {
409 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000410 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800411}
412
413type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700414 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700415 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000416 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800417 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700418 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700419 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900420 relativeInstallPath() string
Martin Stjernholmbf37d162020-03-31 16:05:34 +0100421 skipInstall(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800422}
423
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800424type xref interface {
425 XrefCcFiles() android.Paths
426}
427
Colin Cross6e511a92020-07-27 21:26:48 -0700428type libraryDependencyKind int
429
430const (
431 headerLibraryDependency = iota
432 sharedLibraryDependency
433 staticLibraryDependency
434)
435
436func (k libraryDependencyKind) String() string {
437 switch k {
438 case headerLibraryDependency:
439 return "headerLibraryDependency"
440 case sharedLibraryDependency:
441 return "sharedLibraryDependency"
442 case staticLibraryDependency:
443 return "staticLibraryDependency"
444 default:
445 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
446 }
447}
448
449type libraryDependencyOrder int
450
451const (
452 earlyLibraryDependency = -1
453 normalLibraryDependency = 0
454 lateLibraryDependency = 1
455)
456
457func (o libraryDependencyOrder) String() string {
458 switch o {
459 case earlyLibraryDependency:
460 return "earlyLibraryDependency"
461 case normalLibraryDependency:
462 return "normalLibraryDependency"
463 case lateLibraryDependency:
464 return "lateLibraryDependency"
465 default:
466 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
467 }
468}
469
470// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
471// tags that have a set of predefined tag objects that are reused for each dependency, a
472// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
473// That means that comparing a libraryDependencyTag for equality will only be equal if all
474// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
475// then check individual metadata fields instead.
476type libraryDependencyTag struct {
477 blueprint.BaseDependencyTag
478
479 // These are exported so that fmt.Printf("%#v") can call their String methods.
480 Kind libraryDependencyKind
481 Order libraryDependencyOrder
482
483 wholeStatic bool
484
485 reexportFlags bool
486 explicitlyVersioned bool
487 dataLib bool
488 ndk bool
489
490 staticUnwinder bool
491
492 makeSuffix string
493}
494
495// header returns true if the libraryDependencyTag is tagging a header lib dependency.
496func (d libraryDependencyTag) header() bool {
497 return d.Kind == headerLibraryDependency
498}
499
500// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
501func (d libraryDependencyTag) shared() bool {
502 return d.Kind == sharedLibraryDependency
503}
504
505// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
506func (d libraryDependencyTag) static() bool {
507 return d.Kind == staticLibraryDependency
508}
509
510// dependencyTag is used for tagging miscellanous dependency types that don't fit into
511// libraryDependencyTag. Each tag object is created globally and reused for multiple
512// dependencies (although since the object contains no references, assigning a tag to a
513// variable and modifying it will not modify the original). Users can compare the tag
514// returned by ctx.OtherModuleDependencyTag against the global original
515type dependencyTag struct {
516 blueprint.BaseDependencyTag
517 name string
518}
519
Colin Crossc99deeb2016-04-11 15:06:20 -0700520var (
Colin Cross6e511a92020-07-27 21:26:48 -0700521 genSourceDepTag = dependencyTag{name: "gen source"}
522 genHeaderDepTag = dependencyTag{name: "gen header"}
523 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
524 objDepTag = dependencyTag{name: "obj"}
525 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
526 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
527 reuseObjTag = dependencyTag{name: "reuse objects"}
528 staticVariantTag = dependencyTag{name: "static variant"}
529 vndkExtDepTag = dependencyTag{name: "vndk extends"}
530 dataLibDepTag = dependencyTag{name: "data lib"}
531 runtimeDepTag = dependencyTag{name: "runtime lib"}
532 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700533)
534
Roland Levillainf89cd092019-07-29 16:22:59 +0100535func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700536 ccLibDepTag, ok := depTag.(libraryDependencyTag)
537 return ok && ccLibDepTag.shared()
538}
539
540func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
541 ccLibDepTag, ok := depTag.(libraryDependencyTag)
542 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100543}
544
545func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700546 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100547 return ok && ccDepTag == runtimeDepTag
548}
549
550func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700551 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100552 return ok && ccDepTag == testPerSrcDepTag
553}
554
Colin Crossca860ac2016-01-04 14:34:37 -0800555// Module contains the properties and members used by all C/C++ module types, and implements
556// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
557// to construct the output file. Behavior can be customized with a Customizer interface
558type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700559 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700560 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900561 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900562 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700563
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700564 Properties BaseProperties
565 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700566
Colin Crossca860ac2016-01-04 14:34:37 -0800567 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700568 hod android.HostOrDeviceSupported
569 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700570
Paul Duffina0843f62019-12-13 19:50:38 +0000571 // Allowable SdkMemberTypes of this module type.
572 sdkMemberTypes []android.SdkMemberType
573
Colin Crossca860ac2016-01-04 14:34:37 -0800574 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700575 features []feature
576 compiler compiler
577 linker linker
578 installer installer
579 stl *stl
580 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800581 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800582 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900583 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700584 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700585 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800586
Colin Cross635c3b02016-05-18 15:37:25 -0700587 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800588
Colin Crossb98c8b02016-07-29 13:44:28 -0700589 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700590
591 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800592
593 // Flags used to compile this module
594 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700595
596 // 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 -0800597 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700598 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800599 depsInLinkOrder android.Paths
600
601 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700602 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900603
604 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800605 // Kythe (source file indexer) paths for this compilation module
606 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900607
608 // For apex variants, this is set as apex.min_sdk_version
609 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700610}
611
Ivan Lozano52767be2019-10-18 14:49:46 -0700612func (c *Module) Toc() android.OptionalPath {
613 if c.linker != nil {
614 if library, ok := c.linker.(libraryInterface); ok {
615 return library.toc()
616 }
617 }
618 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
619}
620
621func (c *Module) ApiLevel() string {
622 if c.linker != nil {
623 if stub, ok := c.linker.(*stubDecorator); ok {
624 return stub.properties.ApiLevel
625 }
626 }
627 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
628}
629
630func (c *Module) Static() bool {
631 if c.linker != nil {
632 if library, ok := c.linker.(libraryInterface); ok {
633 return library.static()
634 }
635 }
636 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
637}
638
639func (c *Module) Shared() bool {
640 if c.linker != nil {
641 if library, ok := c.linker.(libraryInterface); ok {
642 return library.shared()
643 }
644 }
645 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
646}
647
648func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000649 if c.stl != nil {
650 return c.stl.Properties.SelectedStl
651 }
652 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700653}
654
655func (c *Module) ToolchainLibrary() bool {
656 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
657 return true
658 }
659 return false
660}
661
662func (c *Module) NdkPrebuiltStl() bool {
663 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
664 return true
665 }
666 return false
667}
668
669func (c *Module) StubDecorator() bool {
670 if _, ok := c.linker.(*stubDecorator); ok {
671 return true
672 }
673 return false
674}
675
676func (c *Module) SdkVersion() string {
677 return String(c.Properties.Sdk_version)
678}
679
Artur Satayev480e25b2020-04-27 18:53:18 +0100680func (c *Module) MinSdkVersion() string {
681 return String(c.Properties.Min_sdk_version)
682}
683
Colin Crossc511bc52020-04-07 16:50:32 +0000684func (c *Module) AlwaysSdk() bool {
685 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
686}
687
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800688func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700689 if c.linker != nil {
690 if library, ok := c.linker.(exportedFlagsProducer); ok {
691 return library.exportedDirs()
692 }
693 }
694 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
695}
696
697func (c *Module) HasStaticVariant() bool {
698 if c.staticVariant != nil {
699 return true
700 }
701 return false
702}
703
704func (c *Module) GetStaticVariant() LinkableInterface {
705 return c.staticVariant
706}
707
708func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
709 c.depsInLinkOrder = depsInLinkOrder
710}
711
712func (c *Module) GetDepsInLinkOrder() []android.Path {
713 return c.depsInLinkOrder
714}
715
716func (c *Module) StubsVersions() []string {
717 if c.linker != nil {
718 if library, ok := c.linker.(*libraryDecorator); ok {
719 return library.Properties.Stubs.Versions
720 }
721 }
722 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
723}
724
725func (c *Module) CcLibrary() bool {
726 if c.linker != nil {
727 if _, ok := c.linker.(*libraryDecorator); ok {
728 return true
729 }
730 }
731 return false
732}
733
734func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700735 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700736 return true
737 }
738 return false
739}
740
Ivan Lozano2b262972019-11-21 12:30:50 -0800741func (c *Module) NonCcVariants() bool {
742 return false
743}
744
Ivan Lozano183a3212019-10-18 14:18:45 -0700745func (c *Module) SetBuildStubs() {
746 if c.linker != nil {
747 if library, ok := c.linker.(*libraryDecorator); ok {
748 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700749 c.Properties.HideFromMake = true
750 c.sanitize = nil
751 c.stl = nil
752 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700753 return
754 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000755 if _, ok := c.linker.(*llndkStubDecorator); ok {
756 c.Properties.HideFromMake = true
757 return
758 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700759 }
760 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
761}
762
Ivan Lozano52767be2019-10-18 14:49:46 -0700763func (c *Module) BuildStubs() bool {
764 if c.linker != nil {
765 if library, ok := c.linker.(*libraryDecorator); ok {
766 return library.buildStubs()
767 }
768 }
769 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
770}
771
Ivan Lozano183a3212019-10-18 14:18:45 -0700772func (c *Module) SetStubsVersions(version string) {
773 if c.linker != nil {
774 if library, ok := c.linker.(*libraryDecorator); ok {
775 library.MutatedProperties.StubsVersion = version
776 return
777 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000778 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
779 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
780 return
781 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700782 }
783 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
784}
785
Jooyung Han03b51852020-02-26 22:45:42 +0900786func (c *Module) StubsVersion() string {
787 if c.linker != nil {
788 if library, ok := c.linker.(*libraryDecorator); ok {
789 return library.MutatedProperties.StubsVersion
790 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000791 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
792 return llndk.libraryDecorator.MutatedProperties.StubsVersion
793 }
Jooyung Han03b51852020-02-26 22:45:42 +0900794 }
795 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
796}
797
Ivan Lozano183a3212019-10-18 14:18:45 -0700798func (c *Module) SetStatic() {
799 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700800 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700801 library.setStatic()
802 return
803 }
804 }
805 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
806}
807
808func (c *Module) SetShared() {
809 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700810 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700811 library.setShared()
812 return
813 }
814 }
815 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
816}
817
818func (c *Module) BuildStaticVariant() bool {
819 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700820 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700821 return library.buildStatic()
822 }
823 }
824 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
825}
826
827func (c *Module) BuildSharedVariant() bool {
828 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700829 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700830 return library.buildShared()
831 }
832 }
833 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
834}
835
836func (c *Module) Module() android.Module {
837 return c
838}
839
Jiyong Parkc20eee32018-09-05 22:36:17 +0900840func (c *Module) OutputFile() android.OptionalPath {
841 return c.outputFile
842}
843
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400844func (c *Module) CoverageFiles() android.Paths {
845 if c.linker != nil {
846 if library, ok := c.linker.(libraryInterface); ok {
847 return library.objs().coverageFiles
848 }
849 }
850 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
851}
852
Ivan Lozano183a3212019-10-18 14:18:45 -0700853var _ LinkableInterface = (*Module)(nil)
854
Jiyong Park719b4462019-01-13 00:39:51 +0900855func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900856 if c.linker != nil {
857 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900858 }
859 return nil
860}
861
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900862func (c *Module) CoverageOutputFile() android.OptionalPath {
863 if c.linker != nil {
864 return c.linker.coverageOutputFilePath()
865 }
866 return android.OptionalPath{}
867}
868
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900869func (c *Module) RelativeInstallPath() string {
870 if c.installer != nil {
871 return c.installer.relativeInstallPath()
872 }
873 return ""
874}
875
Jooyung Han344d5432019-08-23 11:17:39 +0900876func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900877 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900878}
879
Colin Cross36242852017-06-23 15:06:31 -0700880func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700881 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800882 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700883 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800884 }
885 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700886 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800887 }
888 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700889 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800890 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700891 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700892 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700893 }
Colin Cross16b23492016-01-06 14:41:07 -0800894 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700895 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800896 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800897 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700898 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800899 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800900 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700901 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800902 }
Justin Yun8effde42017-06-23 19:24:43 +0900903 if c.vndkdep != nil {
904 c.AddProperties(c.vndkdep.props()...)
905 }
Stephen Craneba090d12017-05-09 15:44:35 -0700906 if c.lto != nil {
907 c.AddProperties(c.lto.props()...)
908 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700909 if c.pgo != nil {
910 c.AddProperties(c.pgo.props()...)
911 }
Colin Crossca860ac2016-01-04 14:34:37 -0800912 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700913 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800914 }
Colin Crossc472d572015-03-17 15:06:21 -0700915
Colin Crossa9d8bee2018-10-02 13:59:46 -0700916 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700917 // Windows builds always prefer 32-bit
918 return class == android.HostCross
Colin Crossa9d8bee2018-10-02 13:59:46 -0700919 })
Colin Cross36242852017-06-23 15:06:31 -0700920 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900921 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900922 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900923 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900924
Colin Cross36242852017-06-23 15:06:31 -0700925 return c
Colin Crossc472d572015-03-17 15:06:21 -0700926}
927
Colin Crossb916a382016-07-29 17:28:03 -0700928// Returns true for dependency roots (binaries)
929// TODO(ccross): also handle dlopenable libraries
930func (c *Module) isDependencyRoot() bool {
931 if root, ok := c.linker.(interface {
932 isDependencyRoot() bool
933 }); ok {
934 return root.isDependencyRoot()
935 }
936 return false
937}
938
Justin Yun5f7f7e82019-11-18 19:52:14 +0900939// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
940// "product" and "vendor" variant modules return true for this function.
941// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
942// "soc_specific: true" and more vendor installed modules are included here.
943// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
944// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700945func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900946 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700947}
948
Colin Crossc511bc52020-04-07 16:50:32 +0000949func (c *Module) canUseSdk() bool {
950 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
951}
952
953func (c *Module) UseSdk() bool {
954 if c.canUseSdk() {
955 return String(c.Properties.Sdk_version) != ""
956 }
957 return false
958}
959
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800960func (c *Module) isCoverageVariant() bool {
961 return c.coverage.Properties.IsCoverageVariant
962}
963
Peter Collingbournead84f972019-12-17 16:46:18 -0800964func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -0700965 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800966}
967
Inseob Kim9516ee92019-05-09 10:56:13 +0900968func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800969 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900970 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800971}
972
Inseob Kim9516ee92019-05-09 10:56:13 +0900973func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800974 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900975 name := c.BaseModuleName()
976 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800977}
978
Inseob Kim9516ee92019-05-09 10:56:13 +0900979func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800980 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900981 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800982}
983
Ivan Lozano52767be2019-10-18 14:49:46 -0700984func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800985 if vndkdep := c.vndkdep; vndkdep != nil {
986 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900987 }
988 return false
989}
990
Yi Kong7e53c572018-02-14 18:16:12 +0800991func (c *Module) isPgoCompile() bool {
992 if pgo := c.pgo; pgo != nil {
993 return pgo.Properties.PgoCompile
994 }
995 return false
996}
997
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800998func (c *Module) isNDKStubLibrary() bool {
999 if _, ok := c.compiler.(*stubDecorator); ok {
1000 return true
1001 }
1002 return false
1003}
1004
Logan Chienf3511742017-10-31 18:04:35 +08001005func (c *Module) isVndkSp() bool {
1006 if vndkdep := c.vndkdep; vndkdep != nil {
1007 return vndkdep.isVndkSp()
1008 }
1009 return false
1010}
1011
1012func (c *Module) isVndkExt() bool {
1013 if vndkdep := c.vndkdep; vndkdep != nil {
1014 return vndkdep.isVndkExt()
1015 }
1016 return false
1017}
1018
Ivan Lozano52767be2019-10-18 14:49:46 -07001019func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001020 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001021}
1022
Logan Chienf3511742017-10-31 18:04:35 +08001023func (c *Module) getVndkExtendsModuleName() string {
1024 if vndkdep := c.vndkdep; vndkdep != nil {
1025 return vndkdep.getVndkExtendsModuleName()
1026 }
1027 return ""
1028}
1029
Justin Yun5f7f7e82019-11-18 19:52:14 +09001030// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +09001031// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -07001032func (c *Module) HasVendorVariant() bool {
1033 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +09001034}
1035
Justin Yun5f7f7e82019-11-18 19:52:14 +09001036const (
1037 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
1038 // against the VNDK.
1039 VendorVariationPrefix = "vendor."
1040
1041 // ProductVariationPrefix is the variant prefix used for /product code that compiles
1042 // against the VNDK.
1043 ProductVariationPrefix = "product."
1044)
1045
1046// Returns true if the module is "product" variant. Usually these modules are installed in /product
1047func (c *Module) inProduct() bool {
1048 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
1049}
1050
1051// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
1052func (c *Module) inVendor() bool {
1053 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
1054}
1055
Yifan Hong1b3348d2020-01-21 15:53:22 -08001056func (c *Module) InRamdisk() bool {
1057 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
1058}
1059
Ivan Lozano52767be2019-10-18 14:49:46 -07001060func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -08001061 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001062}
1063
Yifan Hong1b3348d2020-01-21 15:53:22 -08001064func (c *Module) OnlyInRamdisk() bool {
1065 return c.ModuleBase.InstallInRamdisk()
1066}
1067
Ivan Lozano52767be2019-10-18 14:49:46 -07001068func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001069 return c.ModuleBase.InstallInRecovery()
1070}
1071
Jiyong Park25fc6a92018-11-18 18:02:45 +09001072func (c *Module) IsStubs() bool {
1073 if library, ok := c.linker.(*libraryDecorator); ok {
1074 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001075 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1076 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001077 }
1078 return false
1079}
1080
1081func (c *Module) HasStubsVariants() bool {
1082 if library, ok := c.linker.(*libraryDecorator); ok {
1083 return len(library.Properties.Stubs.Versions) > 0
1084 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001085 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1086 return len(library.Properties.Stubs.Versions) > 0
1087 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001088 return false
1089}
1090
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001091func (c *Module) bootstrap() bool {
1092 return Bool(c.Properties.Bootstrap)
1093}
1094
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001095func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001096 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1097 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1098 return false
1099 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001100 return c.linker != nil && c.linker.nativeCoverage()
1101}
1102
Inseob Kim8471cda2019-11-15 09:59:12 +09001103func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001104 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1105 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001106 }
1107 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001108}
1109
Jiyong Park73c54ee2019-10-22 20:31:18 +09001110func (c *Module) ExportedIncludeDirs() android.Paths {
1111 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1112 return flagsProducer.exportedDirs()
1113 }
Jiyong Park232e7852019-11-04 12:23:40 +09001114 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001115}
1116
1117func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1118 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1119 return flagsProducer.exportedSystemDirs()
1120 }
Jiyong Park232e7852019-11-04 12:23:40 +09001121 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001122}
1123
1124func (c *Module) ExportedFlags() []string {
1125 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1126 return flagsProducer.exportedFlags()
1127 }
Jiyong Park232e7852019-11-04 12:23:40 +09001128 return nil
1129}
1130
1131func (c *Module) ExportedDeps() android.Paths {
1132 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1133 return flagsProducer.exportedDeps()
1134 }
1135 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001136}
1137
Inseob Kimd110f872019-12-06 13:15:38 +09001138func (c *Module) ExportedGeneratedHeaders() android.Paths {
1139 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1140 return flagsProducer.exportedGeneratedHeaders()
1141 }
1142 return nil
1143}
1144
Jiyong Parkf1194352019-02-25 11:05:47 +09001145func isBionic(name string) bool {
1146 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001147 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001148 return true
1149 }
1150 return false
1151}
1152
Martin Stjernholm279de572019-09-10 23:18:20 +01001153func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001154 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001155 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001156 }
1157 return isBionic(name)
1158}
1159
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001160func (c *Module) XrefCcFiles() android.Paths {
1161 return c.kytheFiles
1162}
1163
Colin Crossca860ac2016-01-04 14:34:37 -08001164type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001165 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001166 moduleContextImpl
1167}
1168
Colin Cross37047f12016-12-13 17:06:13 -08001169type depsContext struct {
1170 android.BottomUpMutatorContext
1171 moduleContextImpl
1172}
1173
Colin Crossca860ac2016-01-04 14:34:37 -08001174type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001175 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001176 moduleContextImpl
1177}
1178
Justin Yun5f7f7e82019-11-18 19:52:14 +09001179func (ctx *moduleContext) ProductSpecific() bool {
1180 return ctx.ModuleContext.ProductSpecific() ||
1181 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1182}
1183
Jiyong Park2db76922017-11-08 16:03:48 +09001184func (ctx *moduleContext) SocSpecific() bool {
1185 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001186 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001187}
1188
Colin Crossca860ac2016-01-04 14:34:37 -08001189type moduleContextImpl struct {
1190 mod *Module
1191 ctx BaseModuleContext
1192}
1193
Colin Crossb98c8b02016-07-29 13:44:28 -07001194func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001195 return ctx.mod.toolchain(ctx.ctx)
1196}
1197
1198func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001199 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001200}
1201
1202func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001203 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001204}
1205
Jiyong Park1d1119f2019-07-29 21:27:18 +09001206func (ctx *moduleContextImpl) header() bool {
1207 return ctx.mod.header()
1208}
1209
Inseob Kim7f283f42020-06-01 21:53:49 +09001210func (ctx *moduleContextImpl) binary() bool {
1211 return ctx.mod.binary()
1212}
1213
Inseob Kim1042d292020-06-01 23:23:05 +09001214func (ctx *moduleContextImpl) object() bool {
1215 return ctx.mod.object()
1216}
1217
Jooyung Hanccce2f22020-03-07 03:45:53 +09001218func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001219 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001220}
1221
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001222func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001223 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001224}
1225
1226func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001227 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001228 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001229 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001230 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001231 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001232 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001233 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001234 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001235 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001236 }
1237 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001238}
1239
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001240func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001241 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001242}
Justin Yun8effde42017-06-23 19:24:43 +09001243
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001244func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001245 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001246}
1247
Inseob Kim9516ee92019-05-09 10:56:13 +09001248func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1249 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001250}
1251
Inseob Kim9516ee92019-05-09 10:56:13 +09001252func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1253 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001254}
1255
Inseob Kim9516ee92019-05-09 10:56:13 +09001256func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1257 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001258}
1259
Logan Chienf3511742017-10-31 18:04:35 +08001260func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001261 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001262}
1263
Yi Kong7e53c572018-02-14 18:16:12 +08001264func (ctx *moduleContextImpl) isPgoCompile() bool {
1265 return ctx.mod.isPgoCompile()
1266}
1267
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001268func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1269 return ctx.mod.isNDKStubLibrary()
1270}
1271
Justin Yun8effde42017-06-23 19:24:43 +09001272func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001273 return ctx.mod.isVndkSp()
1274}
1275
1276func (ctx *moduleContextImpl) isVndkExt() bool {
1277 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001278}
1279
Vic Yangefd249e2018-11-12 20:19:56 -08001280func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001281 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001282}
1283
Justin Yun5f7f7e82019-11-18 19:52:14 +09001284func (ctx *moduleContextImpl) inProduct() bool {
1285 return ctx.mod.inProduct()
1286}
1287
1288func (ctx *moduleContextImpl) inVendor() bool {
1289 return ctx.mod.inVendor()
1290}
1291
Yifan Hong1b3348d2020-01-21 15:53:22 -08001292func (ctx *moduleContextImpl) inRamdisk() bool {
1293 return ctx.mod.InRamdisk()
1294}
1295
Jiyong Parkf9332f12018-02-01 00:54:12 +09001296func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001297 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001298}
1299
Logan Chien2f2b8902018-07-10 15:01:19 +08001300// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001301func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001302 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1303 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001304 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001305
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001306 // Coverage builds have extra symbols.
1307 if ctx.mod.isCoverageVariant() {
1308 return false
1309 }
1310
Doug Hornc32c6b02019-01-17 14:44:05 -08001311 if ctx.ctx.Fuchsia() {
1312 return false
1313 }
1314
Logan Chien2f2b8902018-07-10 15:01:19 +08001315 if sanitize := ctx.mod.sanitize; sanitize != nil {
1316 if !sanitize.isVariantOnProductionDevice() {
1317 return false
1318 }
1319 }
1320 if !ctx.ctx.Device() {
1321 // Host modules do not need ABI dumps.
1322 return false
1323 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001324 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001325 // Stubs do not need ABI dumps.
1326 return false
1327 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001328 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001329}
1330
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001331func (ctx *moduleContextImpl) selectedStl() string {
1332 if stl := ctx.mod.stl; stl != nil {
1333 return stl.Properties.SelectedStl
1334 }
1335 return ""
1336}
1337
Ivan Lozanobd721262018-11-27 14:33:03 -08001338func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1339 return ctx.mod.linker.useClangLld(actx)
1340}
1341
Colin Crossce75d2c2016-10-06 16:12:58 -07001342func (ctx *moduleContextImpl) baseModuleName() string {
1343 return ctx.mod.ModuleBase.BaseModuleName()
1344}
1345
Logan Chienf3511742017-10-31 18:04:35 +08001346func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1347 return ctx.mod.getVndkExtendsModuleName()
1348}
1349
Logan Chiene274fc92019-12-03 11:18:32 -08001350func (ctx *moduleContextImpl) isForPlatform() bool {
1351 return ctx.mod.IsForPlatform()
1352}
1353
Jiyong Park58e364a2019-01-19 19:24:06 +09001354func (ctx *moduleContextImpl) apexName() string {
1355 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001356}
1357
Jooyung Hanccce2f22020-03-07 03:45:53 +09001358func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han75568392020-03-20 04:29:24 +09001359 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001360}
1361
Jiyong Parkb0788572018-12-20 22:10:17 +09001362func (ctx *moduleContextImpl) hasStubsVariants() bool {
1363 return ctx.mod.HasStubsVariants()
1364}
1365
1366func (ctx *moduleContextImpl) isStubs() bool {
1367 return ctx.mod.IsStubs()
1368}
1369
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001370func (ctx *moduleContextImpl) bootstrap() bool {
1371 return ctx.mod.bootstrap()
1372}
1373
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001374func (ctx *moduleContextImpl) nativeCoverage() bool {
1375 return ctx.mod.nativeCoverage()
1376}
1377
Colin Cross635c3b02016-05-18 15:37:25 -07001378func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001379 return &Module{
1380 hod: hod,
1381 multilib: multilib,
1382 }
1383}
1384
Colin Cross635c3b02016-05-18 15:37:25 -07001385func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001386 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001387 module.features = []feature{
1388 &tidyFeature{},
1389 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001390 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001391 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001392 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001393 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001394 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001395 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001396 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001397 return module
1398}
1399
Colin Crossce75d2c2016-10-06 16:12:58 -07001400func (c *Module) Prebuilt() *android.Prebuilt {
1401 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1402 return p.prebuilt()
1403 }
1404 return nil
1405}
1406
1407func (c *Module) Name() string {
1408 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001409 if p, ok := c.linker.(interface {
1410 Name(string) string
1411 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001412 name = p.Name(name)
1413 }
1414 return name
1415}
1416
Alex Light3d673592019-01-18 14:37:31 -08001417func (c *Module) Symlinks() []string {
1418 if p, ok := c.installer.(interface {
1419 symlinkList() []string
1420 }); ok {
1421 return p.symlinkList()
1422 }
1423 return nil
1424}
1425
Jeff Gaston294356f2017-09-27 17:05:30 -07001426// orderDeps reorders dependencies into a list such that if module A depends on B, then
1427// A will precede B in the resultant list.
1428// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001429// Note that directSharedDeps should be the analogous static library for each shared lib dep
1430func 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 -07001431 // If A depends on B, then
1432 // Every list containing A will also contain B later in the list
1433 // So, after concatenating all lists, the final instance of B will have come from the same
1434 // original list as the final instance of A
1435 // So, the final instance of B will be later in the concatenation than the final A
1436 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1437 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001438 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001439 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001440 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1441 }
1442 for _, dep := range directSharedDeps {
1443 orderedAllDeps = append(orderedAllDeps, dep)
1444 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001445 }
1446
Colin Crossb6715442017-10-24 11:13:31 -07001447 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001448
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001449 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001450 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001451 // resultant list to only what the caller has chosen to include in directStaticDeps
1452 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001453
1454 return orderedAllDeps, orderedDeclaredDeps
1455}
1456
Ivan Lozano183a3212019-10-18 14:18:45 -07001457func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001458 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001459 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001460 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1461 staticDepFiles := []android.Path{}
1462 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001463 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1464 if dep.OutputFile().Valid() {
1465 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1466 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1467 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001468 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001469 sharedDepFiles := []android.Path{}
1470 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001471 if sharedDep.HasStaticVariant() {
1472 staticAnalogue := sharedDep.GetStaticVariant()
1473 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1474 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001475 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001476 }
1477
1478 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001479 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1480 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001481
1482 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001483}
1484
Roland Levillainf89cd092019-07-29 16:22:59 +01001485func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1486 test, ok := c.linker.(testPerSrc)
1487 return ok && test.isAllTestsVariation()
1488}
1489
Chris Parsons216e10a2020-07-09 17:12:52 -04001490func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001491 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001492 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001493 }); ok {
1494 return p.dataPaths()
1495 }
1496 return nil
1497}
1498
Justin Yun5f7f7e82019-11-18 19:52:14 +09001499func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1500 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1501 // "current", it will append the VNDK version to the name suffix.
1502 var vndkVersion string
1503 var nameSuffix string
1504 if c.inProduct() {
1505 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1506 nameSuffix = productSuffix
1507 } else {
1508 vndkVersion = ctx.DeviceConfig().VndkVersion()
1509 nameSuffix = vendorSuffix
1510 }
1511 if vndkVersion == "current" {
1512 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1513 }
1514 if c.Properties.VndkVersion != vndkVersion {
1515 // add version suffix only if the module is using different vndk version than the
1516 // version in product or vendor partition.
1517 nameSuffix += "." + c.Properties.VndkVersion
1518 }
1519 return nameSuffix
1520}
1521
Colin Cross635c3b02016-05-18 15:37:25 -07001522func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001523 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001524 //
1525 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1526 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1527 // module and return early, as this module does not produce an output file per se.
1528 if c.IsTestPerSrcAllTestsVariation() {
1529 c.outputFile = android.OptionalPath{}
1530 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001531 }
1532
Jooyung Han38002912019-05-16 04:01:54 +09001533 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001534
Inseob Kim64c43952019-08-26 16:52:35 +09001535 c.Properties.SubName = ""
1536
1537 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1538 c.Properties.SubName += nativeBridgeSuffix
1539 }
1540
Justin Yun5f7f7e82019-11-18 19:52:14 +09001541 _, llndk := c.linker.(*llndkStubDecorator)
1542 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1543 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1544 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1545 // added for product variant only when we have vendor and product variants with core
1546 // variant. The suffix is not added for vendor-only or product-only module.
1547 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1548 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001549 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1550 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1551 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001552 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1553 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001554 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001555 c.Properties.SubName += recoverySuffix
Colin Crossc511bc52020-04-07 16:50:32 +00001556 } else if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
1557 c.Properties.SubName += sdkSuffix
Inseob Kim64c43952019-08-26 16:52:35 +09001558 }
1559
Colin Crossca860ac2016-01-04 14:34:37 -08001560 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001561 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001562 moduleContextImpl: moduleContextImpl{
1563 mod: c,
1564 },
1565 }
1566 ctx.ctx = ctx
1567
Colin Crossf18e1102017-11-16 14:33:08 -08001568 deps := c.depsToPaths(ctx)
1569 if ctx.Failed() {
1570 return
1571 }
1572
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001573 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1574 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1575 }
1576
Colin Crossca860ac2016-01-04 14:34:37 -08001577 flags := Flags{
1578 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001579 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001580 }
Colin Crossca860ac2016-01-04 14:34:37 -08001581 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001582 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001583 }
1584 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001585 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001586 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001587 if c.stl != nil {
1588 flags = c.stl.flags(ctx, flags)
1589 }
Colin Cross16b23492016-01-06 14:41:07 -08001590 if c.sanitize != nil {
1591 flags = c.sanitize.flags(ctx, flags)
1592 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001593 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001594 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001595 }
Stephen Craneba090d12017-05-09 15:44:35 -07001596 if c.lto != nil {
1597 flags = c.lto.flags(ctx, flags)
1598 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001599 if c.pgo != nil {
1600 flags = c.pgo.flags(ctx, flags)
1601 }
Colin Crossca860ac2016-01-04 14:34:37 -08001602 for _, feature := range c.features {
1603 flags = feature.flags(ctx, flags)
1604 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001605 if ctx.Failed() {
1606 return
1607 }
1608
Colin Cross4af21ed2019-11-04 09:37:55 -08001609 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1610 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1611 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001612
Colin Cross4af21ed2019-11-04 09:37:55 -08001613 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001614
1615 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001616 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001617 }
1618 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001619 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001620 }
1621
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001622 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001623 // We need access to all the flags seen by a source file.
1624 if c.sabi != nil {
1625 flags = c.sabi.flags(ctx, flags)
1626 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001627
Colin Cross4af21ed2019-11-04 09:37:55 -08001628 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001629
Colin Crossca860ac2016-01-04 14:34:37 -08001630 // Optimization to reduce size of build.ninja
1631 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001632 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1633 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1634 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1635 flags.Local.CFlags = []string{"$cflags"}
1636 flags.Local.CppFlags = []string{"$cppflags"}
1637 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001638
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001639 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001640 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001641 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001642 if ctx.Failed() {
1643 return
1644 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001645 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001646 }
1647
Colin Crossca860ac2016-01-04 14:34:37 -08001648 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001649 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001650 if ctx.Failed() {
1651 return
1652 }
Colin Cross635c3b02016-05-18 15:37:25 -07001653 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001654
1655 // If a lib is directly included in any of the APEXes, unhide the stubs
1656 // variant having the latest version gets visible to make. In addition,
1657 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1658 // force anything in the make world to link against the stubs library.
1659 // (unless it is explicitly referenced via .bootstrap suffix or the
1660 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001661 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001662 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001663 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001664 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001665 c.Properties.HideFromMake = false // unhide
1666 // Note: this is still non-installable
1667 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001668
1669 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1670 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1671 if isSnapshotAware(ctx, c) {
1672 i.collectHeadersForSnapshot(ctx)
1673 }
1674 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001675 }
Colin Cross5049f022015-03-18 13:28:46 -07001676
Inseob Kim1f086e22019-05-09 13:29:15 +09001677 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001678 c.installer.install(ctx, c.outputFile.Path())
1679 if ctx.Failed() {
1680 return
Colin Crossca860ac2016-01-04 14:34:37 -08001681 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001682 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1683 // If the module has been specifically configure to not be installed then
1684 // skip the installation as otherwise it will break when running inside make
1685 // as the output path to install will not be specified. Not all uninstallable
1686 // modules can skip installation as some are needed for resolving make side
1687 // dependencies.
1688 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001689 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001690}
1691
Colin Cross0ea8ba82019-06-06 14:33:29 -07001692func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001693 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001694 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001695 }
Colin Crossca860ac2016-01-04 14:34:37 -08001696 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001697}
1698
Colin Crossca860ac2016-01-04 14:34:37 -08001699func (c *Module) begin(ctx BaseModuleContext) {
1700 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001701 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001702 }
Colin Crossca860ac2016-01-04 14:34:37 -08001703 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001704 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001705 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001706 if c.stl != nil {
1707 c.stl.begin(ctx)
1708 }
Colin Cross16b23492016-01-06 14:41:07 -08001709 if c.sanitize != nil {
1710 c.sanitize.begin(ctx)
1711 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001712 if c.coverage != nil {
1713 c.coverage.begin(ctx)
1714 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001715 if c.sabi != nil {
1716 c.sabi.begin(ctx)
1717 }
Justin Yun8effde42017-06-23 19:24:43 +09001718 if c.vndkdep != nil {
1719 c.vndkdep.begin(ctx)
1720 }
Stephen Craneba090d12017-05-09 15:44:35 -07001721 if c.lto != nil {
1722 c.lto.begin(ctx)
1723 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001724 if c.pgo != nil {
1725 c.pgo.begin(ctx)
1726 }
Colin Crossca860ac2016-01-04 14:34:37 -08001727 for _, feature := range c.features {
1728 feature.begin(ctx)
1729 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001730 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001731 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001732 if err != nil {
1733 ctx.PropertyErrorf("sdk_version", err.Error())
1734 }
Nan Zhang0007d812017-11-07 10:57:05 -08001735 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001736 }
Colin Crossca860ac2016-01-04 14:34:37 -08001737}
1738
Colin Cross37047f12016-12-13 17:06:13 -08001739func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001740 deps := Deps{}
1741
1742 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001743 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001744 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001745 // Add the PGO dependency (the clang_rt.profile runtime library), which
1746 // sometimes depends on symbols from libgcc, before libgcc gets added
1747 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001748 if c.pgo != nil {
1749 deps = c.pgo.deps(ctx, deps)
1750 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001751 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001752 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001753 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001754 if c.stl != nil {
1755 deps = c.stl.deps(ctx, deps)
1756 }
Colin Cross16b23492016-01-06 14:41:07 -08001757 if c.sanitize != nil {
1758 deps = c.sanitize.deps(ctx, deps)
1759 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001760 if c.coverage != nil {
1761 deps = c.coverage.deps(ctx, deps)
1762 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001763 if c.sabi != nil {
1764 deps = c.sabi.deps(ctx, deps)
1765 }
Justin Yun8effde42017-06-23 19:24:43 +09001766 if c.vndkdep != nil {
1767 deps = c.vndkdep.deps(ctx, deps)
1768 }
Stephen Craneba090d12017-05-09 15:44:35 -07001769 if c.lto != nil {
1770 deps = c.lto.deps(ctx, deps)
1771 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001772 for _, feature := range c.features {
1773 deps = feature.deps(ctx, deps)
1774 }
1775
Colin Crossb6715442017-10-24 11:13:31 -07001776 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1777 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1778 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1779 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1780 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1781 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001782 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001783
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001784 for _, lib := range deps.ReexportSharedLibHeaders {
1785 if !inList(lib, deps.SharedLibs) {
1786 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1787 }
1788 }
1789
1790 for _, lib := range deps.ReexportStaticLibHeaders {
1791 if !inList(lib, deps.StaticLibs) {
1792 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1793 }
1794 }
1795
Colin Cross5950f382016-12-13 12:50:57 -08001796 for _, lib := range deps.ReexportHeaderLibHeaders {
1797 if !inList(lib, deps.HeaderLibs) {
1798 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1799 }
1800 }
1801
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001802 for _, gen := range deps.ReexportGeneratedHeaders {
1803 if !inList(gen, deps.GeneratedHeaders) {
1804 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1805 }
1806 }
1807
Colin Crossc99deeb2016-04-11 15:06:20 -07001808 return deps
1809}
1810
Dan Albert7e9d2952016-08-04 13:02:36 -07001811func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001812 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001813 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001814 moduleContextImpl: moduleContextImpl{
1815 mod: c,
1816 },
1817 }
1818 ctx.ctx = ctx
1819
Colin Crossca860ac2016-01-04 14:34:37 -08001820 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001821}
1822
Jiyong Park7ed9de32018-10-15 22:25:07 +09001823// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001824func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001825 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1826 version := name[sharp+1:]
1827 libname := name[:sharp]
1828 return libname, version
1829 }
1830 return name, ""
1831}
1832
Colin Cross1e676be2016-10-12 14:38:15 -07001833func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001834 if !c.Enabled() {
1835 return
1836 }
1837
Colin Cross37047f12016-12-13 17:06:13 -08001838 ctx := &depsContext{
1839 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001840 moduleContextImpl: moduleContextImpl{
1841 mod: c,
1842 },
1843 }
1844 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001845
Colin Crossc99deeb2016-04-11 15:06:20 -07001846 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001847
Dan Albert914449f2016-06-17 16:45:24 -07001848 variantNdkLibs := []string{}
1849 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001850 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001851 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001852 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001853 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001854 // 1. Name of an NDK library that refers to a prebuilt module.
1855 // For each of these, it adds the name of the prebuilt module (which will be in
1856 // prebuilts/ndk) to the list of nonvariant libs.
1857 // 2. Name of an NDK library that refers to an ndk_library module.
1858 // For each of these, it adds the name of the ndk_library module to the list of
1859 // variant libs.
1860 // 3. Anything else (so anything that isn't an NDK library).
1861 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001862 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001863 // The caller can then know to add the variantLibs dependencies differently from the
1864 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001865
Inseob Kim9516ee92019-05-09 10:56:13 +09001866 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001867 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1868
1869 rewriteVendorLibs := func(lib string) string {
1870 if isLlndkLibrary(lib, ctx.Config()) {
1871 return lib + llndkLibrarySuffix
1872 }
1873
1874 // only modules with BOARD_VNDK_VERSION uses snapshot.
1875 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1876 return lib
1877 }
1878
1879 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1880 return snapshot
1881 }
1882
1883 return lib
1884 }
1885
1886 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001887 variantLibs = []string{}
1888 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001889 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001890 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001891 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001892 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1893 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001894 } else if ctx.useVndk() {
1895 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001896 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001897 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001898 if actx.OtherModuleExists(vendorPublicLib) {
1899 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1900 } else {
1901 // This can happen if vendor_public_library module is defined in a
1902 // namespace that isn't visible to the current module. In that case,
1903 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001904 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001905 }
Dan Albert914449f2016-06-17 16:45:24 -07001906 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001907 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001908 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001909 }
1910 }
Dan Albert914449f2016-06-17 16:45:24 -07001911 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001912 }
1913
Inseob Kimeec88e12020-01-22 11:11:29 +09001914 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1915 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1916 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1917 if ctx.useVndk() {
1918 for idx, lib := range deps.RuntimeLibs {
1919 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1920 }
1921 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001922 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001923
Jiyong Park7e636d02019-01-28 16:16:54 +09001924 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001925 if c.linker != nil {
1926 if library, ok := c.linker.(*libraryDecorator); ok {
1927 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001928 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001929 }
1930 }
1931 }
1932
Inseob Kimeec88e12020-01-22 11:11:29 +09001933 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1934 // only modules with BOARD_VNDK_VERSION uses snapshot.
1935 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1936 return lib
1937 }
1938
1939 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1940 return snapshot
1941 }
1942
1943 return lib
1944 }
1945
1946 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001947 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001948 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001949 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001950 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001951 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001952
1953 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1954
Jiyong Park7e636d02019-01-28 16:16:54 +09001955 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001956 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001957 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001958 } else {
1959 actx.AddVariationDependencies(nil, depTag, lib)
1960 }
1961 }
1962
1963 if buildStubs {
1964 // Stubs lib does not have dependency to other static/shared libraries.
1965 // Don't proceed.
1966 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001967 }
Colin Cross5950f382016-12-13 12:50:57 -08001968
Inseob Kimc0907f12019-02-08 21:00:45 +09001969 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001970 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001971
Jiyong Park5d1598f2019-02-25 22:14:17 +09001972 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001973 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001974 if impl, ok := syspropImplLibraries[lib]; ok {
1975 lib = impl
1976 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001977
1978 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1979
Jiyong Park5d1598f2019-02-25 22:14:17 +09001980 actx.AddVariationDependencies([]blueprint.Variation{
1981 {Mutator: "link", Variation: "static"},
1982 }, depTag, lib)
1983 }
1984
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001985 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001986 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001987 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001988 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001989 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001990
1991 if impl, ok := syspropImplLibraries[lib]; ok {
1992 lib = impl
1993 }
1994
Inseob Kimeec88e12020-01-22 11:11:29 +09001995 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1996
Dan Willemsen59339a22018-07-22 21:18:45 -07001997 actx.AddVariationDependencies([]blueprint.Variation{
1998 {Mutator: "link", Variation: "static"},
1999 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002000 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002001
Jooyung Han75568392020-03-20 04:29:24 +09002002 // staticUnwinderDep is treated as staticDep for Q apexes
2003 // so that native libraries/binaries are linked with static unwinder
2004 // because Q libc doesn't have unwinder APIs
2005 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07002006 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002007 actx.AddVariationDependencies([]blueprint.Variation{
2008 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002009 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002010 }
2011
Inseob Kimeec88e12020-01-22 11:11:29 +09002012 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002013 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09002014 actx.AddVariationDependencies([]blueprint.Variation{
2015 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002016 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09002017 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002018
Colin Cross6e511a92020-07-27 21:26:48 -07002019 addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002020 var variations []blueprint.Variation
2021 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09002022 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002023 // Version is explicitly specified. i.e. libFoo#30
2024 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Colin Cross6e511a92020-07-27 21:26:48 -07002025 depTag.explicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09002026 }
2027 actx.AddVariationDependencies(variations, depTag, name)
2028
Jooyung Han03b51852020-02-26 22:45:42 +09002029 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002030 // The stubs library will be used when the depending module is built for APEX and
2031 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09002032 if version == "" && VersionVariantAvailable(c) {
Jooyung Han03b51852020-02-26 22:45:42 +09002033 for _, ver := range stubsVersionsFor(actx.Config())[name] {
2034 // Note that depTag.ExplicitlyVersioned is false in this case.
2035 actx.AddVariationDependencies([]blueprint.Variation{
2036 {Mutator: "link", Variation: "shared"},
2037 {Mutator: "version", Variation: ver},
2038 }, depTag, name)
2039 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002040 }
2041 }
2042
Jiyong Park7ed9de32018-10-15 22:25:07 +09002043 // shared lib names without the #version suffix
2044 var sharedLibNames []string
2045
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002046 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002047 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002048 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002049 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002050 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002051
2052 if impl, ok := syspropImplLibraries[lib]; ok {
2053 lib = impl
2054 }
2055
Jiyong Park73c54ee2019-10-22 20:31:18 +09002056 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002057 sharedLibNames = append(sharedLibNames, name)
2058
Jiyong Park25fc6a92018-11-18 18:02:45 +09002059 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002060 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002061
Jiyong Park7ed9de32018-10-15 22:25:07 +09002062 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002063 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002064 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2065 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2066 // linking against both the stubs lib and the non-stubs lib at the same time.
2067 continue
2068 }
Colin Cross6e511a92020-07-27 21:26:48 -07002069 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
2070 addSharedLibDependencies(depTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09002071 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002072
Dan Willemsen59339a22018-07-22 21:18:45 -07002073 actx.AddVariationDependencies([]blueprint.Variation{
2074 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002075 }, dataLibDepTag, deps.DataLibs...)
2076
2077 actx.AddVariationDependencies([]blueprint.Variation{
2078 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002079 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002080
Colin Cross68861832016-07-08 10:41:41 -07002081 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002082
2083 for _, gen := range deps.GeneratedHeaders {
2084 depTag := genHeaderDepTag
2085 if inList(gen, deps.ReexportGeneratedHeaders) {
2086 depTag = genHeaderExportDepTag
2087 }
2088 actx.AddDependency(c, depTag, gen)
2089 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002090
Colin Cross42d48b72018-08-29 14:10:52 -07002091 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002092
Inseob Kim1042d292020-06-01 23:23:05 +09002093 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2094
Colin Crossc99deeb2016-04-11 15:06:20 -07002095 if deps.CrtBegin != "" {
Inseob Kim1042d292020-06-01 23:23:05 +09002096 actx.AddVariationDependencies(nil, CrtBeginDepTag, rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002097 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002098 if deps.CrtEnd != "" {
Inseob Kim1042d292020-06-01 23:23:05 +09002099 actx.AddVariationDependencies(nil, CrtEndDepTag, rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002100 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002101 if deps.LinkerFlagsFile != "" {
2102 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2103 }
2104 if deps.DynamicLinker != "" {
2105 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002106 }
Dan Albert914449f2016-06-17 16:45:24 -07002107
2108 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002109
2110 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002111 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002112 {Mutator: "ndk_api", Variation: version},
2113 {Mutator: "link", Variation: "shared"},
2114 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002115
2116 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002117 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002118 {Mutator: "ndk_api", Variation: version},
2119 {Mutator: "link", Variation: "shared"},
2120 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002121
2122 if vndkdep := c.vndkdep; vndkdep != nil {
2123 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002124 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002125 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002126 {Mutator: "link", Variation: "shared"},
2127 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002128 }
2129 }
Colin Cross6362e272015-10-29 15:25:03 -07002130}
Colin Cross21b9a242015-03-24 14:15:58 -07002131
Colin Crosse40b4ea2018-10-02 22:25:58 -07002132func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002133 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2134 c.beginMutator(ctx)
2135 }
2136}
2137
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002138// Whether a module can link to another module, taking into
2139// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002140func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2141 tag blueprint.DependencyTag) {
2142
2143 switch t := tag.(type) {
2144 case dependencyTag:
2145 if t != vndkExtDepTag {
2146 return
2147 }
2148 case libraryDependencyTag:
2149 default:
2150 return
2151 }
2152
Ivan Lozano52767be2019-10-18 14:49:46 -07002153 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002154 // Host code is not restricted
2155 return
2156 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002157
2158 // VNDK is cc.Module supported only for now.
2159 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002160 // Though vendor code is limited by the vendor mutator,
2161 // each vendor-available module needs to check
2162 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002163 if ccTo, ok := to.(*Module); ok {
2164 if ccFrom.vndkdep != nil {
2165 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2166 }
2167 } else {
2168 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002169 }
2170 return
2171 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002172 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002173 // Platform code can link to anything
2174 return
2175 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002176 if from.InRamdisk() {
2177 // Ramdisk code is not NDK
2178 return
2179 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002180 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002181 // Recovery code is not NDK
2182 return
2183 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002184 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002185 // These are always allowed
2186 return
2187 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002188 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002189 // These are allowed, but they don't set sdk_version
2190 return
2191 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002192 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002193 // These aren't real libraries, but are the stub shared libraries that are included in
2194 // the NDK.
2195 return
2196 }
Logan Chien834b9a62019-01-14 15:39:03 +08002197
Ivan Lozano52767be2019-10-18 14:49:46 -07002198 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002199 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2200 // to link to libc++ (non-NDK and without sdk_version).
2201 return
2202 }
2203
Ivan Lozano52767be2019-10-18 14:49:46 -07002204 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002205 // NDK code linking to platform code is never okay.
2206 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002207 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002208 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002209 }
2210
2211 // At this point we know we have two NDK libraries, but we need to
2212 // check that we're not linking against anything built against a higher
2213 // API level, as it is only valid to link against older or equivalent
2214 // APIs.
2215
Inseob Kim01a28722018-04-11 09:48:45 +09002216 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002217 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002218 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002219 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002220 // Current can't be linked against by anything else.
2221 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002222 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002223 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002224 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002225 if err != nil {
2226 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002227 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002228 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002229 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002230 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002231 if err != nil {
2232 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002233 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002234 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002235 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002236
Inseob Kim01a28722018-04-11 09:48:45 +09002237 if toApi > fromApi {
2238 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002239 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002240 }
2241 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002242 }
Dan Albert202fe492017-12-15 13:56:59 -08002243
2244 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002245 fromStl := from.SelectedStl()
2246 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002247 if fromStl == "" || toStl == "" {
2248 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002249 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002250 // We can be permissive with the system "STL" since it is only the C++
2251 // ABI layer, but in the future we should make sure that everyone is
2252 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002253 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002254 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002255 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2256 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002257 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002258}
2259
Jiyong Park5fb8c102018-04-09 12:03:06 +09002260// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002261// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2262// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002263// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002264func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2265 check := func(child, parent android.Module) bool {
2266 to, ok := child.(*Module)
2267 if !ok {
2268 // follow thru cc.Defaults, etc.
2269 return true
2270 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002271
Jooyung Hana70f0672019-01-18 15:20:43 +09002272 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2273 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002274 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002275
2276 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002277 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002278 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002279 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002280
Jooyung Han0302a842019-10-30 18:43:49 +09002281 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002282 return false
2283 }
2284
2285 var stringPath []string
2286 for _, m := range ctx.GetWalkPath() {
2287 stringPath = append(stringPath, m.Name())
2288 }
2289 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2290 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2291 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2292 return false
2293 }
2294 if module, ok := ctx.Module().(*Module); ok {
2295 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002296 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002297 ctx.WalkDeps(check)
2298 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002299 }
2300 }
2301}
2302
Colin Crossc99deeb2016-04-11 15:06:20 -07002303// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002304func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002305 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002306
Ivan Lozano183a3212019-10-18 14:18:45 -07002307 directStaticDeps := []LinkableInterface{}
2308 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002309
Inseob Kim69378442019-06-03 19:10:47 +09002310 reexportExporter := func(exporter exportedFlagsProducer) {
2311 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2312 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2313 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2314 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002315 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002316 }
2317
Jooyung Hande34d232020-07-23 13:04:15 +09002318 // For the dependency from platform to apex, use the latest stubs
2319 c.apexSdkVersion = android.FutureApiLevel
2320 if !c.IsForPlatform() {
2321 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2322 }
2323
2324 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2325 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2326 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2327 // (b/144430859)
2328 c.apexSdkVersion = android.FutureApiLevel
2329 }
2330
Colin Crossd11fcda2017-10-23 17:59:01 -07002331 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002332 depName := ctx.OtherModuleName(dep)
2333 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002334
Ivan Lozano52767be2019-10-18 14:49:46 -07002335 ccDep, ok := dep.(LinkableInterface)
2336 if !ok {
2337
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002338 // handling for a few module types that aren't cc Module but that are also supported
2339 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002340 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002341 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002342 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2343 genRule.GeneratedSourceFiles()...)
2344 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002345 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002346 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002347 // Support exported headers from a generated_sources dependency
2348 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002349 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002350 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002351 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002352 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002353 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002354 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002355 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002356 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002357 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2358 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002359 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002360 // 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 +09002361 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002362
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002363 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002364 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002365 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002366 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002367 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002368 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002369 files := genRule.GeneratedSourceFiles()
2370 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002371 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002372 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002373 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 -07002374 }
2375 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002376 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002377 }
Colin Crossca860ac2016-01-04 14:34:37 -08002378 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002379 return
2380 }
2381
Colin Crossfe17f6f2019-03-28 19:30:56 -07002382 if depTag == android.ProtoPluginDepTag {
2383 return
2384 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002385 if depTag == llndkImplDep {
2386 return
2387 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002388
Colin Crossd11fcda2017-10-23 17:59:01 -07002389 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002390 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2391 return
2392 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002393 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002394 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2395 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002396 return
2397 }
2398
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002399 // re-exporting flags
2400 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002401 // reusing objects only make sense for cc.Modules.
2402 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002403 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002404 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002405 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002406 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002407 return
2408 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002409 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002410
Jiyong Parke4bb9862019-02-01 00:31:10 +09002411 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002412 // staticVariants are a cc.Module specific concept.
2413 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002414 c.staticVariant = ccDep
2415 return
2416 }
2417 }
2418
Colin Cross6e511a92020-07-27 21:26:48 -07002419 checkLinkType(ctx, c, ccDep, depTag)
2420
2421 linkFile := ccDep.OutputFile()
2422
2423 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2424 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2425 if libDepTag.staticUnwinder && c.apexSdkVersion > android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002426 return
2427 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002428
Colin Cross6e511a92020-07-27 21:26:48 -07002429 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002430 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002431 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002432 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002433 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002434
2435 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002436 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002437 // Always respect dependency to the versioned stubs (i.e. libX#10)
2438 useThisDep = true
2439 } else if !depHasStubs {
2440 // Use non-stub variant if that is the only choice
2441 // (i.e. depending on a lib without stubs.version property)
2442 useThisDep = true
2443 } else if c.IsForPlatform() {
2444 // If not building for APEX, use stubs only when it is from
2445 // an APEX (and not from platform)
2446 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002447 if c.bootstrap() {
2448 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002449 // always link to non-stub variant
2450 useThisDep = !depIsStubs
2451 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002452 for _, testFor := range c.TestFor() {
2453 // Another exception: if this module is bundled with an APEX, then
2454 // it is linked with the non-stub variant of a module in the APEX
2455 // as if this is part of the APEX.
2456 if android.DirectlyInApex(testFor, depName) {
2457 useThisDep = !depIsStubs
2458 break
2459 }
2460 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002461 } else {
2462 // If building for APEX, use stubs only when it is not from
2463 // the same APEX
2464 useThisDep = (depInSameApex != depIsStubs)
2465 }
2466
Jooyung Han03b51852020-02-26 22:45:42 +09002467 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002468 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Jooyung Han75568392020-03-20 04:29:24 +09002469 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002470 if err != nil {
2471 ctx.OtherModuleErrorf(dep, err.Error())
2472 return
2473 }
2474 if versionToUse != ccDep.StubsVersion() {
2475 useThisDep = false
2476 }
2477 }
2478
Jiyong Park25fc6a92018-11-18 18:02:45 +09002479 if !useThisDep {
2480 return // stop processing this dep
2481 }
2482 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002483 if c.UseVndk() {
2484 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2485 // by default, use current version of LLNDK
2486 versionToUse := ""
2487 versions := stubsVersionsFor(ctx.Config())[depName]
2488 if c.ApexName() != "" && len(versions) > 0 {
2489 // if this is for use_vendor apex && dep has stubsVersions
2490 // apply the same rule of apex sdk enforcement to choose right version
2491 var err error
Jooyung Han75568392020-03-20 04:29:24 +09002492 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002493 if err != nil {
2494 ctx.OtherModuleErrorf(dep, err.Error())
2495 return
2496 }
2497 }
2498 if versionToUse != ccDep.StubsVersion() {
2499 return
2500 }
2501 }
2502 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002503
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002504 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2505
Ivan Lozano52767be2019-10-18 14:49:46 -07002506 // Exporting flags only makes sense for cc.Modules
2507 if _, ok := ccDep.(*Module); ok {
2508 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002509 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002510 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002511 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002512
Colin Cross6e511a92020-07-27 21:26:48 -07002513 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002514 reexportExporter(i)
2515 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2516 // Re-exported shared library headers must be included as well since they can help us with type information
2517 // about template instantiations (instantiated from their headers).
2518 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2519 // scripts.
2520 c.sabi.Properties.ReexportedIncludes = append(
2521 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2522 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002523 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002524 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002525
Colin Cross6e511a92020-07-27 21:26:48 -07002526 var ptr *android.Paths
2527 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002528
Colin Cross6e511a92020-07-27 21:26:48 -07002529 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002530
Colin Cross6e511a92020-07-27 21:26:48 -07002531 switch {
2532 case libDepTag.header():
2533 // nothing
2534 case libDepTag.shared():
2535 ptr = &depPaths.SharedLibs
2536 switch libDepTag.Order {
2537 case earlyLibraryDependency:
2538 ptr = &depPaths.EarlySharedLibs
2539 depPtr = &depPaths.EarlySharedLibsDeps
2540 case normalLibraryDependency:
2541 ptr = &depPaths.SharedLibs
2542 depPtr = &depPaths.SharedLibsDeps
2543 directSharedDeps = append(directSharedDeps, ccDep)
2544 case lateLibraryDependency:
2545 ptr = &depPaths.LateSharedLibs
2546 depPtr = &depPaths.LateSharedLibsDeps
2547 default:
2548 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002549 }
Colin Cross6e511a92020-07-27 21:26:48 -07002550 depFile = ccDep.Toc()
2551 case libDepTag.static():
2552 if libDepTag.wholeStatic {
2553 ptr = &depPaths.WholeStaticLibs
2554 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2555 ctx.ModuleErrorf("module %q not a static library", depName)
2556 return
Inseob Kim752edec2020-03-14 01:30:34 +09002557 }
2558
Colin Cross6e511a92020-07-27 21:26:48 -07002559 // Because the static library objects are included, this only makes sense
2560 // in the context of proper cc.Modules.
2561 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2562 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2563 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2564 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2565 for i := range missingDeps {
2566 missingDeps[i] += postfix
2567 }
2568 ctx.AddMissingDependencies(missingDeps)
2569 }
2570 if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
2571 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
2572 } else {
2573 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2574 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002575 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002576 ctx.ModuleErrorf(
2577 "non-cc.Modules cannot be included as whole static libraries.", depName)
2578 return
2579 }
2580
2581 } else {
2582 switch libDepTag.Order {
2583 case earlyLibraryDependency:
2584 panic(fmt.Errorf("early static libs not suppported"))
2585 case normalLibraryDependency:
2586 // static dependencies will be handled separately so they can be ordered
2587 // using transitive dependencies.
2588 ptr = nil
2589 directStaticDeps = append(directStaticDeps, ccDep)
2590 case lateLibraryDependency:
2591 ptr = &depPaths.LateStaticLibs
2592 default:
2593 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002594 }
2595 }
2596 }
2597
Colin Cross6e511a92020-07-27 21:26:48 -07002598 if libDepTag.static() && !libDepTag.wholeStatic {
2599 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2600 ctx.ModuleErrorf("module %q not a static library", depName)
2601 return
2602 }
Logan Chien43d34c32017-12-20 01:17:32 +08002603
Colin Cross6e511a92020-07-27 21:26:48 -07002604 // When combining coverage files for shared libraries and executables, coverage files
2605 // in static libraries act as if they were whole static libraries. The same goes for
2606 // source based Abi dump files.
2607 if c, ok := ccDep.(*Module); ok {
2608 staticLib := c.linker.(libraryInterface)
2609 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2610 staticLib.objs().coverageFiles...)
2611 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2612 staticLib.objs().sAbiDumpFiles...)
2613 } else if c, ok := ccDep.(LinkableInterface); ok {
2614 // Handle non-CC modules here
2615 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2616 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002617 }
2618 }
2619
Colin Cross6e511a92020-07-27 21:26:48 -07002620 if ptr != nil {
2621 if !linkFile.Valid() {
2622 if !ctx.Config().AllowMissingDependencies() {
2623 ctx.ModuleErrorf("module %q missing output file", depName)
2624 } else {
2625 ctx.AddMissingDependencies([]string{depName})
2626 }
2627 return
2628 }
2629 *ptr = append(*ptr, linkFile.Path())
2630 }
2631
2632 if depPtr != nil {
2633 dep := depFile
2634 if !dep.Valid() {
2635 dep = linkFile
2636 }
2637 *depPtr = append(*depPtr, dep.Path())
2638 }
2639
2640 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2641 switch {
2642 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002643 c.Properties.AndroidMkHeaderLibs = append(
2644 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002645 case libDepTag.shared():
2646 if ccDep.CcLibrary() {
2647 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2648 // Add the dependency to the APEX(es) providing the library so that
2649 // m <module> can trigger building the APEXes as well.
2650 for _, an := range android.GetApexesForModule(depName) {
2651 c.Properties.ApexesProvidingSharedLibs = append(
2652 c.Properties.ApexesProvidingSharedLibs, an)
2653 }
2654 }
2655 }
2656
2657 // Note: the order of libs in this list is not important because
2658 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002659 c.Properties.AndroidMkSharedLibs = append(
2660 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002661 // Record baseLibName for snapshots.
2662 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2663 case libDepTag.static():
2664 if libDepTag.wholeStatic {
2665 c.Properties.AndroidMkWholeStaticLibs = append(
2666 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2667 } else {
2668 c.Properties.AndroidMkStaticLibs = append(
2669 c.Properties.AndroidMkStaticLibs, makeLibName)
2670 }
2671 }
2672 } else {
2673 switch depTag {
2674 case runtimeDepTag:
2675 c.Properties.AndroidMkRuntimeLibs = append(
2676 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2677 // Record baseLibName for snapshots.
2678 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2679 case objDepTag:
2680 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2681 case CrtBeginDepTag:
2682 depPaths.CrtBegin = linkFile
2683 case CrtEndDepTag:
2684 depPaths.CrtEnd = linkFile
2685 case dynamicLinkerDepTag:
2686 depPaths.DynamicLinker = linkFile
2687 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002688 }
Colin Crossca860ac2016-01-04 14:34:37 -08002689 })
2690
Jeff Gaston294356f2017-09-27 17:05:30 -07002691 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002692 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002693
Colin Crossdd84e052017-05-17 13:44:16 -07002694 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002695 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002696 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2697 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002698 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002699 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2700 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002701 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002702 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002703 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002704
2705 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002706 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002707 }
Colin Crossdd84e052017-05-17 13:44:16 -07002708
Colin Crossca860ac2016-01-04 14:34:37 -08002709 return depPaths
2710}
2711
Colin Cross6e511a92020-07-27 21:26:48 -07002712// baseLibName trims known prefixes and suffixes
2713func baseLibName(depName string) string {
2714 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2715 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2716 libName = strings.TrimPrefix(libName, "prebuilt_")
2717 return libName
2718}
2719
2720func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2721 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2722 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2723
2724 libName := baseLibName(depName)
2725 isLLndk := isLlndkLibrary(libName, ctx.Config())
2726 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2727 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2728
2729 if c, ok := ccDep.(*Module); ok {
2730 // Use base module name for snapshots when exporting to Makefile.
2731 if c.isSnapshotPrebuilt() {
2732 baseName := c.BaseModuleName()
2733
2734 if c.IsVndk() {
2735 return baseName + ".vendor"
2736 }
2737
2738 if vendorSuffixModules[baseName] {
2739 return baseName + ".vendor"
2740 } else {
2741 return baseName
2742 }
2743 }
2744 }
2745
2746 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2747 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2748 // core module instead.
2749 return libName
2750 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2751 // The vendor module in Make will have been renamed to not conflict with the core
2752 // module, so update the dependency name here accordingly.
2753 return libName + c.getNameSuffixWithVndkVersion(ctx)
2754 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2755 return libName + vendorPublicLibrarySuffix
2756 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2757 return libName + ramdiskSuffix
2758 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2759 return libName + recoverySuffix
2760 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2761 return libName + nativeBridgeSuffix
2762 } else {
2763 return libName
2764 }
2765}
2766
Colin Crossca860ac2016-01-04 14:34:37 -08002767func (c *Module) InstallInData() bool {
2768 if c.installer == nil {
2769 return false
2770 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002771 return c.installer.inData()
2772}
2773
2774func (c *Module) InstallInSanitizerDir() bool {
2775 if c.installer == nil {
2776 return false
2777 }
2778 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002779 return true
2780 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002781 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002782}
2783
Yifan Hong1b3348d2020-01-21 15:53:22 -08002784func (c *Module) InstallInRamdisk() bool {
2785 return c.InRamdisk()
2786}
2787
Jiyong Parkf9332f12018-02-01 00:54:12 +09002788func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002789 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002790}
2791
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002792func (c *Module) SkipInstall() {
2793 if c.installer == nil {
2794 c.ModuleBase.SkipInstall()
2795 return
2796 }
2797 c.installer.skipInstall(c)
2798}
2799
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002800func (c *Module) HostToolPath() android.OptionalPath {
2801 if c.installer == nil {
2802 return android.OptionalPath{}
2803 }
2804 return c.installer.hostToolPath()
2805}
2806
Nan Zhangd4e641b2017-07-12 12:55:28 -07002807func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2808 return c.outputFile
2809}
2810
Colin Cross41955e82019-05-29 14:40:35 -07002811func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2812 switch tag {
2813 case "":
2814 if c.outputFile.Valid() {
2815 return android.Paths{c.outputFile.Path()}, nil
2816 }
2817 return android.Paths{}, nil
2818 default:
2819 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002820 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002821}
2822
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002823func (c *Module) static() bool {
2824 if static, ok := c.linker.(interface {
2825 static() bool
2826 }); ok {
2827 return static.static()
2828 }
2829 return false
2830}
2831
Jiyong Park379de2f2018-12-19 02:47:14 +09002832func (c *Module) staticBinary() bool {
2833 if static, ok := c.linker.(interface {
2834 staticBinary() bool
2835 }); ok {
2836 return static.staticBinary()
2837 }
2838 return false
2839}
2840
Jiyong Park1d1119f2019-07-29 21:27:18 +09002841func (c *Module) header() bool {
2842 if h, ok := c.linker.(interface {
2843 header() bool
2844 }); ok {
2845 return h.header()
2846 }
2847 return false
2848}
2849
Inseob Kim7f283f42020-06-01 21:53:49 +09002850func (c *Module) binary() bool {
2851 if b, ok := c.linker.(interface {
2852 binary() bool
2853 }); ok {
2854 return b.binary()
2855 }
2856 return false
2857}
2858
Inseob Kim1042d292020-06-01 23:23:05 +09002859func (c *Module) object() bool {
2860 if o, ok := c.linker.(interface {
2861 object() bool
2862 }); ok {
2863 return o.object()
2864 }
2865 return false
2866}
2867
Jooyung Han38002912019-05-16 04:01:54 +09002868func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002869 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002870 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2871 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002872 return "native:vndk"
2873 }
Jooyung Han38002912019-05-16 04:01:54 +09002874 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002875 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002876 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002877 if Bool(c.VendorProperties.Vendor_available) {
2878 return "native:vndk"
2879 }
2880 return "native:vndk_private"
2881 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002882 if c.inProduct() {
2883 return "native:product"
2884 }
Jooyung Han38002912019-05-16 04:01:54 +09002885 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002886 } else if c.InRamdisk() {
2887 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002888 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002889 return "native:recovery"
2890 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2891 return "native:ndk:none:none"
2892 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2893 //family, link := getNdkStlFamilyAndLinkType(c)
2894 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002895 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002896 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002897 } else {
2898 return "native:platform"
2899 }
2900}
2901
Jiyong Park9d452992018-10-03 00:38:19 +09002902// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002903// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002904func (c *Module) IsInstallableToApex() bool {
2905 if shared, ok := c.linker.(interface {
2906 shared() bool
2907 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002908 // Stub libs and prebuilt libs in a versioned SDK are not
2909 // installable to APEX even though they are shared libs.
2910 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002911 } else if _, ok := c.linker.(testPerSrc); ok {
2912 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002913 }
2914 return false
2915}
2916
Jiyong Parka90ca002019-10-07 15:47:24 +09002917func (c *Module) AvailableFor(what string) bool {
2918 if linker, ok := c.linker.(interface {
2919 availableFor(string) bool
2920 }); ok {
2921 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2922 } else {
2923 return c.ApexModuleBase.AvailableFor(what)
2924 }
2925}
2926
Jiyong Park62304bb2020-04-13 16:19:48 +09002927func (c *Module) TestFor() []string {
2928 if test, ok := c.linker.(interface {
2929 testFor() []string
2930 }); ok {
2931 return test.testFor()
2932 } else {
2933 return c.ApexModuleBase.TestFor()
2934 }
2935}
2936
Paul Duffin0cb37b92020-03-04 14:52:46 +00002937// Return true if the module is ever installable.
2938func (c *Module) EverInstallable() bool {
2939 return c.installer != nil &&
2940 // Check to see whether the module is actually ever installable.
2941 c.installer.everInstallable()
2942}
2943
Inseob Kim1f086e22019-05-09 13:29:15 +09002944func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002945 ret := c.EverInstallable() &&
2946 // Check to see whether the module has been configured to not be installed.
2947 proptools.BoolDefault(c.Properties.Installable, true) &&
2948 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002949
2950 // The platform variant doesn't need further condition. Apex variants however might not
2951 // be installable because it will likely to be included in the APEX and won't appear
2952 // in the system partition.
2953 if c.IsForPlatform() {
2954 return ret
2955 }
2956
2957 // Special case for modules that are configured to be installed to /data, which includes
2958 // test modules. For these modules, both APEX and non-APEX variants are considered as
2959 // installable. This is because even the APEX variants won't be included in the APEX, but
2960 // will anyway be installed to /data/*.
2961 // See b/146995717
2962 if c.InstallInData() {
2963 return ret
2964 }
2965
2966 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002967}
2968
Logan Chien41eabe62019-04-10 13:33:58 +08002969func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2970 if c.linker != nil {
2971 if library, ok := c.linker.(*libraryDecorator); ok {
2972 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2973 }
2974 }
2975}
2976
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002977func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002978 depTag := ctx.OtherModuleDependencyTag(dep)
2979 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2980
2981 if cc, ok := dep.(*Module); ok {
2982 if cc.HasStubsVariants() {
2983 if isLibDepTag && libDepTag.shared() {
2984 // dynamic dep to a stubs lib crosses APEX boundary
2985 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002986 }
Colin Cross6e511a92020-07-27 21:26:48 -07002987 if IsRuntimeDepTag(depTag) {
2988 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002989 return false
2990 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002991 }
Colin Crossaac32222020-07-29 12:51:56 -07002992 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07002993 // shared_lib dependency from a static lib is considered as crossing
2994 // the APEX boundary because the dependency doesn't actually is
2995 // linked; the dependency is used only during the compilation phase.
2996 return false
2997 }
2998 }
2999 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09003000 // We don't track beyond LLNDK
3001 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003002 }
3003 return true
3004}
3005
Jooyung Han749dc692020-04-15 11:03:39 +09003006// b/154667674: refactor this to handle "current" in a consistent way
3007func decodeSdkVersionString(ctx android.BaseModuleContext, versionString string) (int, error) {
3008 if versionString == "" {
3009 return 0, fmt.Errorf("not specified")
3010 }
3011 if versionString == "current" {
3012 if ctx.Config().PlatformSdkCodename() == "REL" {
3013 return ctx.Config().PlatformSdkVersionInt(), nil
3014 }
3015 return android.FutureApiLevel, nil
3016 }
3017 return android.ApiStrToNum(ctx, versionString)
3018}
3019
3020func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error {
3021 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3022 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3023 return nil
3024 }
3025 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3026 if c.ToolchainLibrary() {
3027 return nil
3028 }
3029 // We don't check for prebuilt modules
3030 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3031 return nil
3032 }
3033 minSdkVersion := c.MinSdkVersion()
3034 if minSdkVersion == "apex_inherit" {
3035 return nil
3036 }
3037 if minSdkVersion == "" {
3038 // JNI libs within APK-in-APEX fall into here
3039 // Those are okay to set sdk_version instead
3040 // We don't have to check if this is a SDK variant because
3041 // non-SDK variant resets sdk_version, which works too.
3042 minSdkVersion = c.SdkVersion()
3043 }
3044 ver, err := decodeSdkVersionString(ctx, minSdkVersion)
3045 if err != nil {
3046 return err
3047 }
3048 if ver > sdkVersion {
3049 return fmt.Errorf("newer SDK(%v)", ver)
3050 }
3051 return nil
3052}
3053
Colin Cross2ba19d92015-05-07 15:44:20 -07003054//
Colin Crosscfad1192015-11-02 16:43:11 -08003055// Defaults
3056//
Colin Crossca860ac2016-01-04 14:34:37 -08003057type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003058 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003059 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003060 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003061}
3062
Patrice Arrudac249c712019-03-19 17:00:29 -07003063// cc_defaults provides a set of properties that can be inherited by other cc
3064// modules. A module can use the properties from a cc_defaults using
3065// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3066// merged (when possible) by prepending the default module's values to the
3067// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003068func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003069 return DefaultsFactory()
3070}
3071
Colin Cross36242852017-06-23 15:06:31 -07003072func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003073 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003074
Colin Cross36242852017-06-23 15:06:31 -07003075 module.AddProperties(props...)
3076 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003077 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003078 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003079 &BaseCompilerProperties{},
3080 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003081 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003082 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003083 &StaticProperties{},
3084 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003085 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003086 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003087 &TestProperties{},
3088 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003089 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003090 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003091 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003092 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003093 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003094 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003095 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003096 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003097 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003098 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003099 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003100 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003101 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003102 )
Colin Crosscfad1192015-11-02 16:43:11 -08003103
Jooyung Hancc372c52019-09-25 15:18:44 +09003104 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003105
3106 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003107}
3108
Jiyong Park6a43f042017-10-12 23:05:00 +09003109func squashVendorSrcs(m *Module) {
3110 if lib, ok := m.compiler.(*libraryDecorator); ok {
3111 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3112 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3113
3114 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3115 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003116
3117 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3118 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003119 }
3120}
3121
Jiyong Parkf9332f12018-02-01 00:54:12 +09003122func squashRecoverySrcs(m *Module) {
3123 if lib, ok := m.compiler.(*libraryDecorator); ok {
3124 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3125 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3126
3127 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3128 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003129
3130 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3131 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003132 }
3133}
3134
Colin Cross7228ecd2019-11-18 16:00:16 -08003135var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003136
Colin Cross7228ecd2019-11-18 16:00:16 -08003137func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Patrice Arruda807cfd22020-07-28 18:35:53 +00003138 // Validation check
Logan Chienf3511742017-10-31 18:04:35 +08003139 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09003140 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08003141
3142 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003143 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09003144 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003145 }
Logan Chienf3511742017-10-31 18:04:35 +08003146
3147 if vndkdep := m.vndkdep; vndkdep != nil {
3148 if vndkdep.isVndk() {
Justin Yun0ecf0b22020-02-28 15:07:59 +09003149 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08003150 if !vndkdep.isVndkExt() {
3151 mctx.PropertyErrorf("vndk",
3152 "must set `extends: \"...\"` to vndk extension")
Justin Yun0ecf0b22020-02-28 15:07:59 +09003153 } else if m.VendorProperties.Vendor_available != nil {
3154 mctx.PropertyErrorf("vendor_available",
3155 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08003156 }
3157 } else {
3158 if vndkdep.isVndkExt() {
3159 mctx.PropertyErrorf("vndk",
Justin Yun0ecf0b22020-02-28 15:07:59 +09003160 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08003161 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08003162 }
3163 if m.VendorProperties.Vendor_available == nil {
3164 mctx.PropertyErrorf("vndk",
3165 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08003166 }
3167 }
3168 } else {
3169 if vndkdep.isVndkSp() {
3170 mctx.PropertyErrorf("vndk",
3171 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08003172 }
3173 if vndkdep.isVndkExt() {
3174 mctx.PropertyErrorf("vndk",
3175 "must set `enabled: true` to set `extends: %q`",
3176 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08003177 }
Justin Yun8effde42017-06-23 19:24:43 +09003178 }
3179 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003180
Jiyong Parkf9332f12018-02-01 00:54:12 +09003181 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08003182 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09003183 var recoveryVariantNeeded bool = false
3184
Inseob Kim64c43952019-08-26 16:52:35 +09003185 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09003186 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09003187
3188 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09003189 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
3190 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
3191 if boardVndkVersion == "current" {
3192 boardVndkVersion = platformVndkVersion
3193 }
3194 if productVndkVersion == "current" {
3195 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09003196 }
3197
Justin Yun5f7f7e82019-11-18 19:52:14 +09003198 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003199 // If the device isn't compiling against the VNDK, we always
3200 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003201 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003202 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003203 // LL-NDK stubs only exist in the vendor and product variants,
3204 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09003205 vendorVariants = append(vendorVariants,
3206 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003207 boardVndkVersion,
3208 )
3209 productVariants = append(productVariants,
3210 platformVndkVersion,
3211 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09003212 )
Jiyong Park2a454122017-10-19 15:59:33 +09003213 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
3214 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09003215 vendorVariants = append(vendorVariants,
3216 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003217 boardVndkVersion,
3218 )
3219 productVariants = append(productVariants,
3220 platformVndkVersion,
3221 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09003222 )
Inseob Kimeec88e12020-01-22 11:11:29 +09003223 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09003224 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
3225 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09003226 if snapshot, ok := m.linker.(interface {
3227 version() string
3228 }); ok {
3229 vendorVariants = append(vendorVariants, snapshot.version())
3230 } else {
3231 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
3232 }
Justin Yun0ecf0b22020-02-28 15:07:59 +09003233 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003234 // This will be available in /system, /vendor and /product
3235 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003236 coreVariantNeeded = true
Inseob Kim85708802020-06-02 00:06:15 +09003237
3238 // We assume that modules under proprietary paths are compatible for
3239 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
3240 // PLATFORM_VNDK_VERSION.
3241 if isVendorProprietaryPath(mctx.ModuleDir()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003242 vendorVariants = append(vendorVariants, boardVndkVersion)
Inseob Kim85708802020-06-02 00:06:15 +09003243 } else {
3244 vendorVariants = append(vendorVariants, platformVndkVersion)
3245 }
3246
3247 // vendor_available modules are also available to /product.
3248 productVariants = append(productVariants, platformVndkVersion)
3249 // VNDK is always PLATFORM_VNDK_VERSION
3250 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003251 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09003252 }
Logan Chienf3511742017-10-31 18:04:35 +08003253 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09003254 // This will be available in /vendor (or /odm) only
Inseob Kimf3044b62020-06-11 13:51:52 +09003255
3256 // kernel_headers is a special module type whose exported headers
3257 // are coming from DeviceKernelHeaders() which is always vendor
3258 // dependent. They'll always have both vendor variants.
3259 // For other modules, we assume that modules under proprietary
3260 // paths are compatible for BOARD_VNDK_VERSION. The other modules
3261 // are regarded as AOSP, which is PLATFORM_VNDK_VERSION.
3262 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
3263 vendorVariants = append(vendorVariants,
3264 platformVndkVersion,
3265 boardVndkVersion,
3266 )
3267 } else if isVendorProprietaryPath(mctx.ModuleDir()) {
Inseob Kim85708802020-06-02 00:06:15 +09003268 vendorVariants = append(vendorVariants, boardVndkVersion)
3269 } else {
3270 vendorVariants = append(vendorVariants, platformVndkVersion)
3271 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003272 } else {
3273 // This is either in /system (or similar: /data), or is a
3274 // modules built with the NDK. Modules built with the NDK
3275 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003276 coreVariantNeeded = true
3277 }
3278
Justin Yun5f7f7e82019-11-18 19:52:14 +09003279 if boardVndkVersion != "" && productVndkVersion != "" {
3280 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
3281 // The module has "product_specific: true" that does not create core variant.
3282 coreVariantNeeded = false
3283 productVariants = append(productVariants, productVndkVersion)
3284 }
3285 } else {
3286 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
3287 // restriction to use system libs.
3288 // No product variants defined in this case.
3289 productVariants = []string{}
3290 }
3291
Yifan Hong1b3348d2020-01-21 15:53:22 -08003292 if Bool(m.Properties.Ramdisk_available) {
3293 ramdiskVariantNeeded = true
3294 }
3295
3296 if m.ModuleBase.InstallInRamdisk() {
3297 ramdiskVariantNeeded = true
3298 coreVariantNeeded = false
3299 }
3300
Jiyong Parkf9332f12018-02-01 00:54:12 +09003301 if Bool(m.Properties.Recovery_available) {
3302 recoveryVariantNeeded = true
3303 }
3304
3305 if m.ModuleBase.InstallInRecovery() {
3306 recoveryVariantNeeded = true
3307 coreVariantNeeded = false
3308 }
3309
Inseob Kim64c43952019-08-26 16:52:35 +09003310 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003311 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
3312 }
3313
3314 for _, variant := range android.FirstUniqueStrings(productVariants) {
3315 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003316 }
Colin Cross7228ecd2019-11-18 16:00:16 -08003317
Yifan Hong1b3348d2020-01-21 15:53:22 -08003318 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08003319 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
3320 m.Properties.CoreVariantNeeded = coreVariantNeeded
3321}
3322
3323func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
3324 return c.Properties.CoreVariantNeeded
3325}
3326
Yifan Hong1b3348d2020-01-21 15:53:22 -08003327func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3328 return c.Properties.RamdiskVariantNeeded
3329}
3330
Colin Cross7228ecd2019-11-18 16:00:16 -08003331func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3332 return c.Properties.RecoveryVariantNeeded
3333}
3334
3335func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003336 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003337}
3338
3339func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3340 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003341 if variant == android.RamdiskVariation {
3342 m.MakeAsPlatform()
3343 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003344 m.MakeAsPlatform()
3345 squashRecoverySrcs(m)
3346 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003347 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003348 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3349 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003350
3351 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3352 // Hide other vendor variants to avoid collision.
3353 vndkVersion := ctx.DeviceConfig().VndkVersion()
3354 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3355 m.Properties.HideFromMake = true
3356 m.SkipInstall()
3357 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003358 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3359 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3360 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3361 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003362 }
3363}
3364
Jiyong Park2286afd2020-06-16 21:58:53 +09003365func (c *Module) IsSdkVariant() bool {
3366 return c.Properties.IsSdkVariant
3367}
3368
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003369func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003370 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003371 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3372 }
Colin Cross6510f912017-11-29 00:27:14 -08003373 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003374}
3375
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003376func kytheExtractAllFactory() android.Singleton {
3377 return &kytheExtractAllSingleton{}
3378}
3379
3380type kytheExtractAllSingleton struct {
3381}
3382
3383func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3384 var xrefTargets android.Paths
3385 ctx.VisitAllModules(func(module android.Module) {
3386 if ccModule, ok := module.(xref); ok {
3387 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3388 }
3389 })
3390 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3391 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003392 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003393 }
3394}
3395
Colin Cross06a931b2015-10-28 17:23:31 -07003396var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003397var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003398var BoolPtr = proptools.BoolPtr
3399var String = proptools.String
3400var StringPtr = proptools.StringPtr