blob: 81885509b5b80f3a6283d3da3682b445f2d56ae9 [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()
Colin Crossd1f898e2020-08-18 18:35:15 -070050 ctx.BottomUp("version_selector", versionSelectorMutator).Parallel()
51 ctx.BottomUp("version", versionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070052 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090053 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090054 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
55 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070056 })
Colin Cross16b23492016-01-06 14:41:07 -080057
Paul Duffin036e7002019-12-19 19:16:28 +000058 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070059 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
60 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080061
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070062 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
63 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
64
Mitch Phillipsbfeade62019-05-01 14:42:05 -070065 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
66 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
67
Jiyong Park1d1119f2019-07-29 21:27:18 +090068 // cfi mutator shouldn't run before sanitizers that return true for
69 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000070 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
71 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
72
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080073 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
74 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
75
Colin Cross1e676be2016-10-12 14:38:15 -070076 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
77 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080078
Colin Cross0b908332019-06-19 23:00:20 -070079 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090080 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080081
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080082 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080083 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070084
85 ctx.TopDown("lto_deps", ltoDepsMutator)
86 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090087
88 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070089 })
Colin Crossb98c8b02016-07-29 13:44:28 -070090
Sasha Smundak2a4549e2018-11-05 16:49:08 -080091 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070092}
93
Colin Crossca860ac2016-01-04 14:34:37 -080094type Deps struct {
95 SharedLibs, LateSharedLibs []string
96 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080097 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080098 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070099
Chris Parsons79d66a52020-06-05 17:26:16 -0400100 // Used for data dependencies adjacent to tests
101 DataLibs []string
102
Yo Chiang219968c2020-09-22 18:45:04 +0800103 // Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
104 SystemSharedLibs []string
105
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800106 StaticUnwinderIfLegacy bool
107
Colin Cross5950f382016-12-13 12:50:57 -0800108 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700109
Colin Cross81413472016-04-11 14:37:39 -0700110 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700111
Dan Willemsenb40aab62016-04-20 14:21:14 -0700112 GeneratedSources []string
113 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900114 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700115
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700116 ReexportGeneratedHeaders []string
117
Colin Cross97ba0732015-03-23 17:50:24 -0700118 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700119
120 // Used for host bionic
121 LinkerFlagsFile string
122 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700123}
124
Colin Crossca860ac2016-01-04 14:34:37 -0800125type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700126 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900127 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700128 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900129 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700130 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700131 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700132
Colin Cross26c34ed2016-09-30 17:10:16 -0700133 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100134 Objs Objects
135 // Paths to .o files in dependencies that provide them. Note that these lists
136 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800137 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700138 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700139
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100140 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
141 // the libs from all whole_static_lib dependencies.
142 WholeStaticLibsFromPrebuilts android.Paths
143
Colin Cross26c34ed2016-09-30 17:10:16 -0700144 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700145 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900146 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700147
Inseob Kimd110f872019-12-06 13:15:38 +0900148 Flags []string
149 IncludeDirs android.Paths
150 SystemIncludeDirs android.Paths
151 ReexportedDirs android.Paths
152 ReexportedSystemDirs android.Paths
153 ReexportedFlags []string
154 ReexportedGeneratedHeaders android.Paths
155 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700156
Colin Cross26c34ed2016-09-30 17:10:16 -0700157 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700158 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700159
160 // Path to the file container flags to use with the linker
161 LinkerFlagsFile android.OptionalPath
162
163 // Path to the dynamic linker binary
164 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700165}
166
Colin Cross4af21ed2019-11-04 09:37:55 -0800167// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
168// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
169// command line so they can be overridden by the local module flags).
170type LocalOrGlobalFlags struct {
171 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700172 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800173 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700174 CFlags []string // Flags that apply to C and C++ source files
175 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
176 ConlyFlags []string // Flags that apply to C source files
177 CppFlags []string // Flags that apply to C++ source files
178 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700179 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800180}
181
182type Flags struct {
183 Local LocalOrGlobalFlags
184 Global LocalOrGlobalFlags
185
186 aidlFlags []string // Flags that apply to aidl source files
187 rsFlags []string // Flags that apply to renderscript source files
188 libFlags []string // Flags to add libraries early to the link order
189 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
190 TidyFlags []string // Flags that apply to clang-tidy
191 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700192
Colin Crossc3199482017-03-30 15:03:04 -0700193 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800194 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700195 SystemIncludeFlags []string
196
Oliver Nguyen04526782020-04-21 12:40:27 -0700197 Toolchain config.Toolchain
198 Tidy bool
199 GcovCoverage bool
200 SAbiDump bool
201 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800202
203 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800204 DynamicLinker string
205
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700206 CFlagsDeps android.Paths // Files depended on by compiler flags
207 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800208
Dan Willemsen98ab3112019-08-27 21:20:40 -0700209 AssemblerWithCpp bool
210 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800211
Colin Cross19878da2019-03-28 14:45:07 -0700212 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700213 protoC bool // Whether to use C instead of C++
214 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700215
216 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200217 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700218}
219
Colin Crossca860ac2016-01-04 14:34:37 -0800220// Properties used to compile all C or C++ modules
221type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700222 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800223 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700224
Colin Crossc511bc52020-04-07 16:50:32 +0000225 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
226 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800227 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700228
Jooyung Han379660c2020-04-21 15:24:00 +0900229 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
230 Min_sdk_version *string
231
Colin Crossc511bc52020-04-07 16:50:32 +0000232 // If true, always create an sdk variant and don't create a platform variant.
233 Sdk_variant_only *bool
234
Jiyong Parkde866cb2018-12-07 23:08:36 +0900235 AndroidMkSharedLibs []string `blueprint:"mutated"`
236 AndroidMkStaticLibs []string `blueprint:"mutated"`
237 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
238 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700239 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900240 HideFromMake bool `blueprint:"mutated"`
241 PreventInstall bool `blueprint:"mutated"`
242 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700243
Yo Chiang219968c2020-09-22 18:45:04 +0800244 // Set by DepsMutator.
245 AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
246
Justin Yun5f7f7e82019-11-18 19:52:14 +0900247 ImageVariationPrefix string `blueprint:"mutated"`
248 VndkVersion string `blueprint:"mutated"`
249 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800250
251 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
252 // file
253 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900254
Yifan Hong1b3348d2020-01-21 15:53:22 -0800255 // Make this module available when building for ramdisk
256 Ramdisk_available *bool
257
Jiyong Parkf9332f12018-02-01 00:54:12 +0900258 // Make this module available when building for recovery
259 Recovery_available *bool
260
Colin Crossae6c5202019-11-20 13:35:50 -0800261 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800262 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800263 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800264 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900265 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900266
267 // Allows this module to use non-APEX version of libraries. Useful
268 // for building binaries that are started before APEXes are activated.
269 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900270
271 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
272 // see soong/cc/config/vndk.go
273 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900274
275 // Used by vendor snapshot to record dependencies from snapshot modules.
276 SnapshotSharedLibs []string `blueprint:"mutated"`
277 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000278
279 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000280
281 // Set by factories of module types that can only be referenced from variants compiled against
282 // the SDK.
283 AlwaysSdk bool `blueprint:"mutated"`
284
285 // Variant is an SDK variant created by sdkMutator
286 IsSdkVariant bool `blueprint:"mutated"`
287 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
288 // variant to have a ".sdk" suffix.
289 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700290
291 // Normally Soong uses the directory structure to decide which modules
292 // should be included (framework) or excluded (non-framework) from the
293 // vendor snapshot, but this property allows a partner to exclude a
294 // module normally thought of as a framework module from the vendor
295 // snapshot.
296 Exclude_from_vendor_snapshot *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700297}
298
299type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900300 // whether this module should be allowed to be directly depended by other
301 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900302 // In addition, this module should be allowed to be directly depended by
303 // product modules with `product_specific: true`.
304 // If set to true, three variants will be built separately, one like
305 // normal, another limited to the set of libraries and headers
306 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700307 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900308 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700309 // so it shouldn't have any unversioned runtime dependencies, or
310 // make assumptions about the system that may not be true in the
311 // future.
312 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900313 // If set to false, this module becomes inaccessible from /vendor or /product
314 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900315 //
316 // Default value is true when vndk: {enabled: true} or vendor: true.
317 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700318 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900319 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700320 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900321
322 // whether this module is capable of being loaded with other instance
323 // (possibly an older version) of the same module in the same process.
324 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
325 // can be double loaded in a vendor process if the library is also a
326 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
327 // explicitly marked as `double_loadable: true` by the owner, or the dependency
328 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
329 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800330}
331
Colin Crossca860ac2016-01-04 14:34:37 -0800332type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800333 static() bool
334 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900335 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900336 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900337 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700338 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900339 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700340 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800341 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700342 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800343 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900344 isLlndk(config android.Config) bool
345 isLlndkPublic(config android.Config) bool
346 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900347 isVndk() bool
348 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800349 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900350 inProduct() bool
351 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800352 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900353 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800354 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700355 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700356 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800357 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800358 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800359 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800360 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800361 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700362 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700363 apexSdkVersion() android.ApiLevel
Jiyong Parkb0788572018-12-20 22:10:17 +0900364 hasStubsVariants() bool
365 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900366 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800367 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700368 nativeCoverage() bool
Colin Cross56a83212020-09-15 18:30:11 -0700369 directlyInAnyApex() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800370}
371
372type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700373 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800374 ModuleContextIntf
375}
376
377type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700378 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800379 ModuleContextIntf
380}
381
Colin Cross37047f12016-12-13 17:06:13 -0800382type DepsContext interface {
383 android.BottomUpMutatorContext
384 ModuleContextIntf
385}
386
Colin Crossca860ac2016-01-04 14:34:37 -0800387type feature interface {
388 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800389 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800390 flags(ctx ModuleContext, flags Flags) Flags
391 props() []interface{}
392}
393
394type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700395 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800396 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800397 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700398 compilerProps() []interface{}
399
Colin Cross76fada02016-07-27 10:31:13 -0700400 appendCflags([]string)
401 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700402 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800403}
404
405type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700406 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800407 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700408 linkerFlags(ctx ModuleContext, flags Flags) Flags
409 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800410 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700411
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700412 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700413 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900414 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700415
416 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900417 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000418
419 // Get the deps that have been explicitly specified in the properties.
420 // Only updates the
421 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
422}
423
424type specifiedDeps struct {
425 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000426 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800427}
428
429type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700430 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700431 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000432 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800433 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700434 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700435 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900436 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100437 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800438}
439
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800440type xref interface {
441 XrefCcFiles() android.Paths
442}
443
Colin Cross6e511a92020-07-27 21:26:48 -0700444type libraryDependencyKind int
445
446const (
447 headerLibraryDependency = iota
448 sharedLibraryDependency
449 staticLibraryDependency
450)
451
452func (k libraryDependencyKind) String() string {
453 switch k {
454 case headerLibraryDependency:
455 return "headerLibraryDependency"
456 case sharedLibraryDependency:
457 return "sharedLibraryDependency"
458 case staticLibraryDependency:
459 return "staticLibraryDependency"
460 default:
461 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
462 }
463}
464
465type libraryDependencyOrder int
466
467const (
468 earlyLibraryDependency = -1
469 normalLibraryDependency = 0
470 lateLibraryDependency = 1
471)
472
473func (o libraryDependencyOrder) String() string {
474 switch o {
475 case earlyLibraryDependency:
476 return "earlyLibraryDependency"
477 case normalLibraryDependency:
478 return "normalLibraryDependency"
479 case lateLibraryDependency:
480 return "lateLibraryDependency"
481 default:
482 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
483 }
484}
485
486// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
487// tags that have a set of predefined tag objects that are reused for each dependency, a
488// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
489// That means that comparing a libraryDependencyTag for equality will only be equal if all
490// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
491// then check individual metadata fields instead.
492type libraryDependencyTag struct {
493 blueprint.BaseDependencyTag
494
495 // These are exported so that fmt.Printf("%#v") can call their String methods.
496 Kind libraryDependencyKind
497 Order libraryDependencyOrder
498
499 wholeStatic bool
500
501 reexportFlags bool
502 explicitlyVersioned bool
503 dataLib bool
504 ndk bool
505
506 staticUnwinder bool
507
508 makeSuffix string
509}
510
511// header returns true if the libraryDependencyTag is tagging a header lib dependency.
512func (d libraryDependencyTag) header() bool {
513 return d.Kind == headerLibraryDependency
514}
515
516// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
517func (d libraryDependencyTag) shared() bool {
518 return d.Kind == sharedLibraryDependency
519}
520
521// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
522func (d libraryDependencyTag) static() bool {
523 return d.Kind == staticLibraryDependency
524}
525
526// dependencyTag is used for tagging miscellanous dependency types that don't fit into
527// libraryDependencyTag. Each tag object is created globally and reused for multiple
528// dependencies (although since the object contains no references, assigning a tag to a
529// variable and modifying it will not modify the original). Users can compare the tag
530// returned by ctx.OtherModuleDependencyTag against the global original
531type dependencyTag struct {
532 blueprint.BaseDependencyTag
533 name string
534}
535
Colin Crossc99deeb2016-04-11 15:06:20 -0700536var (
Colin Cross6e511a92020-07-27 21:26:48 -0700537 genSourceDepTag = dependencyTag{name: "gen source"}
538 genHeaderDepTag = dependencyTag{name: "gen header"}
539 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
540 objDepTag = dependencyTag{name: "obj"}
541 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
542 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
543 reuseObjTag = dependencyTag{name: "reuse objects"}
544 staticVariantTag = dependencyTag{name: "static variant"}
545 vndkExtDepTag = dependencyTag{name: "vndk extends"}
546 dataLibDepTag = dependencyTag{name: "data lib"}
547 runtimeDepTag = dependencyTag{name: "runtime lib"}
548 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Cross56a83212020-09-15 18:30:11 -0700549 testForDepTag = dependencyTag{name: "test for apex"}
550
551 stubImplDepTag = copyDirectlyInAnyApexDependencyTag{name: "stub_impl"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700552)
553
Colin Cross56a83212020-09-15 18:30:11 -0700554type copyDirectlyInAnyApexDependencyTag dependencyTag
555
556func (copyDirectlyInAnyApexDependencyTag) CopyDirectlyInAnyApex() {}
557
558var _ android.CopyDirectlyInAnyApexTag = copyDirectlyInAnyApexDependencyTag{}
559
Roland Levillainf89cd092019-07-29 16:22:59 +0100560func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700561 ccLibDepTag, ok := depTag.(libraryDependencyTag)
562 return ok && ccLibDepTag.shared()
563}
564
565func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
566 ccLibDepTag, ok := depTag.(libraryDependencyTag)
567 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100568}
569
570func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700571 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100572 return ok && ccDepTag == runtimeDepTag
573}
574
575func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700576 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100577 return ok && ccDepTag == testPerSrcDepTag
578}
579
Colin Crossca860ac2016-01-04 14:34:37 -0800580// Module contains the properties and members used by all C/C++ module types, and implements
581// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
582// to construct the output file. Behavior can be customized with a Customizer interface
583type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700584 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700585 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900586 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900587 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700588
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700589 Properties BaseProperties
590 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700591
Colin Crossca860ac2016-01-04 14:34:37 -0800592 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700593 hod android.HostOrDeviceSupported
594 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700595
Paul Duffina0843f62019-12-13 19:50:38 +0000596 // Allowable SdkMemberTypes of this module type.
597 sdkMemberTypes []android.SdkMemberType
598
Colin Crossca860ac2016-01-04 14:34:37 -0800599 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700600 features []feature
601 compiler compiler
602 linker linker
603 installer installer
604 stl *stl
605 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800606 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800607 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900608 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700609 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700610 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800611
Colin Cross635c3b02016-05-18 15:37:25 -0700612 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800613
Colin Crossb98c8b02016-07-29 13:44:28 -0700614 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700615
616 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800617
618 // Flags used to compile this module
619 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700620
621 // 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 -0800622 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700623 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800624 depsInLinkOrder android.Paths
625
626 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700627 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900628
629 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800630 // Kythe (source file indexer) paths for this compilation module
631 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900632
633 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700634 apexSdkVersion android.ApiLevel
Colin Cross56a83212020-09-15 18:30:11 -0700635
636 hideApexVariantFromMake bool
Colin Crossc472d572015-03-17 15:06:21 -0700637}
638
Ivan Lozano52767be2019-10-18 14:49:46 -0700639func (c *Module) Toc() android.OptionalPath {
640 if c.linker != nil {
641 if library, ok := c.linker.(libraryInterface); ok {
642 return library.toc()
643 }
644 }
645 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
646}
647
648func (c *Module) ApiLevel() string {
649 if c.linker != nil {
650 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -0700651 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -0700652 }
653 }
654 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
655}
656
657func (c *Module) Static() bool {
658 if c.linker != nil {
659 if library, ok := c.linker.(libraryInterface); ok {
660 return library.static()
661 }
662 }
663 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
664}
665
666func (c *Module) Shared() bool {
667 if c.linker != nil {
668 if library, ok := c.linker.(libraryInterface); ok {
669 return library.shared()
670 }
671 }
672 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
673}
674
675func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000676 if c.stl != nil {
677 return c.stl.Properties.SelectedStl
678 }
679 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700680}
681
682func (c *Module) ToolchainLibrary() bool {
683 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
684 return true
685 }
686 return false
687}
688
689func (c *Module) NdkPrebuiltStl() bool {
690 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
691 return true
692 }
693 return false
694}
695
696func (c *Module) StubDecorator() bool {
697 if _, ok := c.linker.(*stubDecorator); ok {
698 return true
699 }
700 return false
701}
702
703func (c *Module) SdkVersion() string {
704 return String(c.Properties.Sdk_version)
705}
706
Artur Satayev480e25b2020-04-27 18:53:18 +0100707func (c *Module) MinSdkVersion() string {
708 return String(c.Properties.Min_sdk_version)
709}
710
Dan Albert92fe7402020-07-15 13:33:30 -0700711func (c *Module) SplitPerApiLevel() bool {
Colin Cross1348ce32020-10-01 13:37:16 -0700712 if !c.canUseSdk() {
713 return false
714 }
Dan Albert92fe7402020-07-15 13:33:30 -0700715 if linker, ok := c.linker.(*objectLinker); ok {
716 return linker.isCrt()
717 }
718 return false
719}
720
Colin Crossc511bc52020-04-07 16:50:32 +0000721func (c *Module) AlwaysSdk() bool {
722 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
723}
724
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800725func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700726 if c.linker != nil {
727 if library, ok := c.linker.(exportedFlagsProducer); ok {
728 return library.exportedDirs()
729 }
730 }
731 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
732}
733
734func (c *Module) HasStaticVariant() bool {
735 if c.staticVariant != nil {
736 return true
737 }
738 return false
739}
740
741func (c *Module) GetStaticVariant() LinkableInterface {
742 return c.staticVariant
743}
744
745func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
746 c.depsInLinkOrder = depsInLinkOrder
747}
748
749func (c *Module) GetDepsInLinkOrder() []android.Path {
750 return c.depsInLinkOrder
751}
752
753func (c *Module) StubsVersions() []string {
754 if c.linker != nil {
755 if library, ok := c.linker.(*libraryDecorator); ok {
756 return library.Properties.Stubs.Versions
757 }
Colin Crossd48fe732020-09-23 20:37:24 -0700758 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
759 return library.Properties.Stubs.Versions
760 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700761 }
762 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
763}
764
765func (c *Module) CcLibrary() bool {
766 if c.linker != nil {
767 if _, ok := c.linker.(*libraryDecorator); ok {
768 return true
769 }
Colin Crossd48fe732020-09-23 20:37:24 -0700770 if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
771 return true
772 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700773 }
774 return false
775}
776
777func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700778 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700779 return true
780 }
781 return false
782}
783
Ivan Lozano2b262972019-11-21 12:30:50 -0800784func (c *Module) NonCcVariants() bool {
785 return false
786}
787
Ivan Lozano183a3212019-10-18 14:18:45 -0700788func (c *Module) SetBuildStubs() {
789 if c.linker != nil {
790 if library, ok := c.linker.(*libraryDecorator); ok {
791 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700792 c.Properties.HideFromMake = true
793 c.sanitize = nil
794 c.stl = nil
795 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700796 return
797 }
Colin Crossd48fe732020-09-23 20:37:24 -0700798 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
799 library.MutatedProperties.BuildStubs = true
800 c.Properties.HideFromMake = true
801 c.sanitize = nil
802 c.stl = nil
803 c.Properties.PreventInstall = true
804 return
805 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000806 if _, ok := c.linker.(*llndkStubDecorator); ok {
807 c.Properties.HideFromMake = true
808 return
809 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700810 }
811 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
812}
813
Ivan Lozano52767be2019-10-18 14:49:46 -0700814func (c *Module) BuildStubs() bool {
815 if c.linker != nil {
816 if library, ok := c.linker.(*libraryDecorator); ok {
817 return library.buildStubs()
818 }
Colin Crossd48fe732020-09-23 20:37:24 -0700819 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
820 return library.buildStubs()
821 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700822 }
823 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
824}
825
Colin Crossd1f898e2020-08-18 18:35:15 -0700826func (c *Module) SetAllStubsVersions(versions []string) {
827 if library, ok := c.linker.(*libraryDecorator); ok {
828 library.MutatedProperties.AllStubsVersions = versions
829 return
830 }
Colin Crossd48fe732020-09-23 20:37:24 -0700831 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
832 library.MutatedProperties.AllStubsVersions = versions
833 return
834 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700835 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
836 llndk.libraryDecorator.MutatedProperties.AllStubsVersions = versions
837 return
838 }
839}
840
841func (c *Module) AllStubsVersions() []string {
842 if library, ok := c.linker.(*libraryDecorator); ok {
843 return library.MutatedProperties.AllStubsVersions
844 }
Colin Crossd48fe732020-09-23 20:37:24 -0700845 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
846 return library.MutatedProperties.AllStubsVersions
847 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700848 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
849 return llndk.libraryDecorator.MutatedProperties.AllStubsVersions
850 }
851 return nil
852}
853
854func (c *Module) SetStubsVersion(version string) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700855 if c.linker != nil {
856 if library, ok := c.linker.(*libraryDecorator); ok {
857 library.MutatedProperties.StubsVersion = version
858 return
859 }
Colin Crossd48fe732020-09-23 20:37:24 -0700860 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
861 library.MutatedProperties.StubsVersion = version
862 return
863 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000864 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
865 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
866 return
867 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700868 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700869 panic(fmt.Errorf("SetStubsVersion called on non-library module: %q", c.BaseModuleName()))
Ivan Lozano183a3212019-10-18 14:18:45 -0700870}
871
Jooyung Han03b51852020-02-26 22:45:42 +0900872func (c *Module) StubsVersion() string {
873 if c.linker != nil {
874 if library, ok := c.linker.(*libraryDecorator); ok {
875 return library.MutatedProperties.StubsVersion
876 }
Colin Crossd48fe732020-09-23 20:37:24 -0700877 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
878 return library.MutatedProperties.StubsVersion
879 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000880 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
881 return llndk.libraryDecorator.MutatedProperties.StubsVersion
882 }
Jooyung Han03b51852020-02-26 22:45:42 +0900883 }
884 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
885}
886
Ivan Lozano183a3212019-10-18 14:18:45 -0700887func (c *Module) SetStatic() {
888 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700889 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700890 library.setStatic()
891 return
892 }
893 }
894 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
895}
896
897func (c *Module) SetShared() {
898 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700899 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700900 library.setShared()
901 return
902 }
903 }
904 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
905}
906
907func (c *Module) BuildStaticVariant() bool {
908 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700909 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700910 return library.buildStatic()
911 }
912 }
913 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
914}
915
916func (c *Module) BuildSharedVariant() bool {
917 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700918 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700919 return library.buildShared()
920 }
921 }
922 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
923}
924
925func (c *Module) Module() android.Module {
926 return c
927}
928
Jiyong Parkc20eee32018-09-05 22:36:17 +0900929func (c *Module) OutputFile() android.OptionalPath {
930 return c.outputFile
931}
932
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400933func (c *Module) CoverageFiles() android.Paths {
934 if c.linker != nil {
935 if library, ok := c.linker.(libraryInterface); ok {
936 return library.objs().coverageFiles
937 }
938 }
939 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
940}
941
Ivan Lozano183a3212019-10-18 14:18:45 -0700942var _ LinkableInterface = (*Module)(nil)
943
Jiyong Park719b4462019-01-13 00:39:51 +0900944func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900945 if c.linker != nil {
946 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900947 }
948 return nil
949}
950
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900951func (c *Module) CoverageOutputFile() android.OptionalPath {
952 if c.linker != nil {
953 return c.linker.coverageOutputFilePath()
954 }
955 return android.OptionalPath{}
956}
957
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900958func (c *Module) RelativeInstallPath() string {
959 if c.installer != nil {
960 return c.installer.relativeInstallPath()
961 }
962 return ""
963}
964
Jooyung Han344d5432019-08-23 11:17:39 +0900965func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900966 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900967}
968
Colin Cross36242852017-06-23 15:06:31 -0700969func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700970 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800971 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700972 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800973 }
974 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700975 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800976 }
977 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700978 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800979 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700980 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700981 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700982 }
Colin Cross16b23492016-01-06 14:41:07 -0800983 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700984 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800985 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800986 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700987 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800988 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800989 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700990 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800991 }
Justin Yun8effde42017-06-23 19:24:43 +0900992 if c.vndkdep != nil {
993 c.AddProperties(c.vndkdep.props()...)
994 }
Stephen Craneba090d12017-05-09 15:44:35 -0700995 if c.lto != nil {
996 c.AddProperties(c.lto.props()...)
997 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700998 if c.pgo != nil {
999 c.AddProperties(c.pgo.props()...)
1000 }
Colin Crossca860ac2016-01-04 14:34:37 -08001001 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -07001002 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001003 }
Colin Crossc472d572015-03-17 15:06:21 -07001004
Jiyong Park1613e552020-09-14 19:43:17 +09001005 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -07001006 // Windows builds always prefer 32-bit
Jiyong Park1613e552020-09-14 19:43:17 +09001007 return os == android.Windows
Colin Crossa9d8bee2018-10-02 13:59:46 -07001008 })
Colin Cross36242852017-06-23 15:06:31 -07001009 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +09001010 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001011 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +09001012 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +09001013
Colin Cross36242852017-06-23 15:06:31 -07001014 return c
Colin Crossc472d572015-03-17 15:06:21 -07001015}
1016
Colin Crossb916a382016-07-29 17:28:03 -07001017// Returns true for dependency roots (binaries)
1018// TODO(ccross): also handle dlopenable libraries
1019func (c *Module) isDependencyRoot() bool {
1020 if root, ok := c.linker.(interface {
1021 isDependencyRoot() bool
1022 }); ok {
1023 return root.isDependencyRoot()
1024 }
1025 return false
1026}
1027
Justin Yun5f7f7e82019-11-18 19:52:14 +09001028// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
1029// "product" and "vendor" variant modules return true for this function.
1030// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
1031// "soc_specific: true" and more vendor installed modules are included here.
1032// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
1033// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -07001034func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +09001035 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001036}
1037
Colin Crossc511bc52020-04-07 16:50:32 +00001038func (c *Module) canUseSdk() bool {
1039 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
1040}
1041
1042func (c *Module) UseSdk() bool {
1043 if c.canUseSdk() {
Colin Cross1348ce32020-10-01 13:37:16 -07001044 return String(c.Properties.Sdk_version) != ""
Colin Crossc511bc52020-04-07 16:50:32 +00001045 }
1046 return false
1047}
1048
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001049func (c *Module) isCoverageVariant() bool {
1050 return c.coverage.Properties.IsCoverageVariant
1051}
1052
Peter Collingbournead84f972019-12-17 16:46:18 -08001053func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -07001054 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001055}
1056
Inseob Kim9516ee92019-05-09 10:56:13 +09001057func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001058 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001059 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001060}
1061
Inseob Kim9516ee92019-05-09 10:56:13 +09001062func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001063 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001064 name := c.BaseModuleName()
1065 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001066}
1067
Inseob Kim9516ee92019-05-09 10:56:13 +09001068func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001069 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +09001070 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001071}
1072
Ivan Lozano52767be2019-10-18 14:49:46 -07001073func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001074 if vndkdep := c.vndkdep; vndkdep != nil {
1075 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001076 }
1077 return false
1078}
1079
Yi Kong7e53c572018-02-14 18:16:12 +08001080func (c *Module) isPgoCompile() bool {
1081 if pgo := c.pgo; pgo != nil {
1082 return pgo.Properties.PgoCompile
1083 }
1084 return false
1085}
1086
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001087func (c *Module) isNDKStubLibrary() bool {
1088 if _, ok := c.compiler.(*stubDecorator); ok {
1089 return true
1090 }
1091 return false
1092}
1093
Logan Chienf3511742017-10-31 18:04:35 +08001094func (c *Module) isVndkSp() bool {
1095 if vndkdep := c.vndkdep; vndkdep != nil {
1096 return vndkdep.isVndkSp()
1097 }
1098 return false
1099}
1100
1101func (c *Module) isVndkExt() bool {
1102 if vndkdep := c.vndkdep; vndkdep != nil {
1103 return vndkdep.isVndkExt()
1104 }
1105 return false
1106}
1107
Ivan Lozano52767be2019-10-18 14:49:46 -07001108func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001109 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001110}
1111
Logan Chienf3511742017-10-31 18:04:35 +08001112func (c *Module) getVndkExtendsModuleName() string {
1113 if vndkdep := c.vndkdep; vndkdep != nil {
1114 return vndkdep.getVndkExtendsModuleName()
1115 }
1116 return ""
1117}
1118
Jiyong Park25fc6a92018-11-18 18:02:45 +09001119func (c *Module) IsStubs() bool {
1120 if library, ok := c.linker.(*libraryDecorator); ok {
1121 return library.buildStubs()
Colin Crossd48fe732020-09-23 20:37:24 -07001122 } else if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1123 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001124 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1125 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001126 }
1127 return false
1128}
1129
1130func (c *Module) HasStubsVariants() bool {
1131 if library, ok := c.linker.(*libraryDecorator); ok {
1132 return len(library.Properties.Stubs.Versions) > 0
1133 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001134 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1135 return len(library.Properties.Stubs.Versions) > 0
1136 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001137 return false
1138}
1139
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001140func (c *Module) bootstrap() bool {
1141 return Bool(c.Properties.Bootstrap)
1142}
1143
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001144func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001145 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1146 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1147 return false
1148 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001149 return c.linker != nil && c.linker.nativeCoverage()
1150}
1151
Inseob Kim8471cda2019-11-15 09:59:12 +09001152func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001153 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1154 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001155 }
1156 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001157}
1158
Jiyong Park73c54ee2019-10-22 20:31:18 +09001159func (c *Module) ExportedIncludeDirs() android.Paths {
1160 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1161 return flagsProducer.exportedDirs()
1162 }
Jiyong Park232e7852019-11-04 12:23:40 +09001163 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001164}
1165
1166func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1167 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1168 return flagsProducer.exportedSystemDirs()
1169 }
Jiyong Park232e7852019-11-04 12:23:40 +09001170 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001171}
1172
1173func (c *Module) ExportedFlags() []string {
1174 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1175 return flagsProducer.exportedFlags()
1176 }
Jiyong Park232e7852019-11-04 12:23:40 +09001177 return nil
1178}
1179
1180func (c *Module) ExportedDeps() android.Paths {
1181 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1182 return flagsProducer.exportedDeps()
1183 }
1184 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001185}
1186
Inseob Kimd110f872019-12-06 13:15:38 +09001187func (c *Module) ExportedGeneratedHeaders() android.Paths {
1188 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1189 return flagsProducer.exportedGeneratedHeaders()
1190 }
1191 return nil
1192}
1193
Bill Peckham945441c2020-08-31 16:07:58 -07001194func (c *Module) ExcludeFromVendorSnapshot() bool {
1195 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1196}
1197
Jiyong Parkf1194352019-02-25 11:05:47 +09001198func isBionic(name string) bool {
1199 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001200 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001201 return true
1202 }
1203 return false
1204}
1205
Martin Stjernholm279de572019-09-10 23:18:20 +01001206func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001207 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001208 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001209 }
1210 return isBionic(name)
1211}
1212
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001213func (c *Module) XrefCcFiles() android.Paths {
1214 return c.kytheFiles
1215}
1216
Colin Crossca860ac2016-01-04 14:34:37 -08001217type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001218 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001219 moduleContextImpl
1220}
1221
Colin Cross37047f12016-12-13 17:06:13 -08001222type depsContext struct {
1223 android.BottomUpMutatorContext
1224 moduleContextImpl
1225}
1226
Colin Crossca860ac2016-01-04 14:34:37 -08001227type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001228 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001229 moduleContextImpl
1230}
1231
1232type moduleContextImpl struct {
1233 mod *Module
1234 ctx BaseModuleContext
1235}
1236
Colin Crossb98c8b02016-07-29 13:44:28 -07001237func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001238 return ctx.mod.toolchain(ctx.ctx)
1239}
1240
1241func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001242 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001243}
1244
1245func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001246 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001247}
1248
Jiyong Park1d1119f2019-07-29 21:27:18 +09001249func (ctx *moduleContextImpl) header() bool {
1250 return ctx.mod.header()
1251}
1252
Inseob Kim7f283f42020-06-01 21:53:49 +09001253func (ctx *moduleContextImpl) binary() bool {
1254 return ctx.mod.binary()
1255}
1256
Inseob Kim1042d292020-06-01 23:23:05 +09001257func (ctx *moduleContextImpl) object() bool {
1258 return ctx.mod.object()
1259}
1260
Jooyung Hanccce2f22020-03-07 03:45:53 +09001261func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001262 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001263}
1264
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001265func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001266 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001267}
1268
1269func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001270 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001271 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001272 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001273 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001274 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001275 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001276 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001277 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001278 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001279 }
1280 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001281}
1282
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001283func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001284 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001285}
Justin Yun8effde42017-06-23 19:24:43 +09001286
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001287func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001288 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001289}
1290
Inseob Kim9516ee92019-05-09 10:56:13 +09001291func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1292 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001293}
1294
Inseob Kim9516ee92019-05-09 10:56:13 +09001295func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1296 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001297}
1298
Inseob Kim9516ee92019-05-09 10:56:13 +09001299func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1300 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001301}
1302
Logan Chienf3511742017-10-31 18:04:35 +08001303func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001304 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001305}
1306
Yi Kong7e53c572018-02-14 18:16:12 +08001307func (ctx *moduleContextImpl) isPgoCompile() bool {
1308 return ctx.mod.isPgoCompile()
1309}
1310
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001311func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1312 return ctx.mod.isNDKStubLibrary()
1313}
1314
Justin Yun8effde42017-06-23 19:24:43 +09001315func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001316 return ctx.mod.isVndkSp()
1317}
1318
1319func (ctx *moduleContextImpl) isVndkExt() bool {
1320 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001321}
1322
Vic Yangefd249e2018-11-12 20:19:56 -08001323func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001324 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001325}
1326
Logan Chien2f2b8902018-07-10 15:01:19 +08001327// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001328func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001329 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1330 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001331 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001332
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001333 // Coverage builds have extra symbols.
1334 if ctx.mod.isCoverageVariant() {
1335 return false
1336 }
1337
Doug Hornc32c6b02019-01-17 14:44:05 -08001338 if ctx.ctx.Fuchsia() {
1339 return false
1340 }
1341
Logan Chien2f2b8902018-07-10 15:01:19 +08001342 if sanitize := ctx.mod.sanitize; sanitize != nil {
1343 if !sanitize.isVariantOnProductionDevice() {
1344 return false
1345 }
1346 }
1347 if !ctx.ctx.Device() {
1348 // Host modules do not need ABI dumps.
1349 return false
1350 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001351 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001352 // Stubs do not need ABI dumps.
1353 return false
1354 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001355 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001356}
1357
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001358func (ctx *moduleContextImpl) selectedStl() string {
1359 if stl := ctx.mod.stl; stl != nil {
1360 return stl.Properties.SelectedStl
1361 }
1362 return ""
1363}
1364
Ivan Lozanobd721262018-11-27 14:33:03 -08001365func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1366 return ctx.mod.linker.useClangLld(actx)
1367}
1368
Colin Crossce75d2c2016-10-06 16:12:58 -07001369func (ctx *moduleContextImpl) baseModuleName() string {
1370 return ctx.mod.ModuleBase.BaseModuleName()
1371}
1372
Logan Chienf3511742017-10-31 18:04:35 +08001373func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1374 return ctx.mod.getVndkExtendsModuleName()
1375}
1376
Logan Chiene274fc92019-12-03 11:18:32 -08001377func (ctx *moduleContextImpl) isForPlatform() bool {
Colin Cross56a83212020-09-15 18:30:11 -07001378 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
Logan Chiene274fc92019-12-03 11:18:32 -08001379}
1380
Colin Crosse07f2312020-08-13 11:24:56 -07001381func (ctx *moduleContextImpl) apexVariationName() string {
Colin Cross56a83212020-09-15 18:30:11 -07001382 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
Jiyong Park25fc6a92018-11-18 18:02:45 +09001383}
1384
Dan Albertc8060532020-07-22 22:32:17 -07001385func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001386 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001387}
1388
Jiyong Parkb0788572018-12-20 22:10:17 +09001389func (ctx *moduleContextImpl) hasStubsVariants() bool {
1390 return ctx.mod.HasStubsVariants()
1391}
1392
1393func (ctx *moduleContextImpl) isStubs() bool {
1394 return ctx.mod.IsStubs()
1395}
1396
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001397func (ctx *moduleContextImpl) bootstrap() bool {
1398 return ctx.mod.bootstrap()
1399}
1400
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001401func (ctx *moduleContextImpl) nativeCoverage() bool {
1402 return ctx.mod.nativeCoverage()
1403}
1404
Colin Cross56a83212020-09-15 18:30:11 -07001405func (ctx *moduleContextImpl) directlyInAnyApex() bool {
1406 return ctx.mod.DirectlyInAnyApex()
1407}
1408
Colin Cross635c3b02016-05-18 15:37:25 -07001409func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001410 return &Module{
1411 hod: hod,
1412 multilib: multilib,
1413 }
1414}
1415
Colin Cross635c3b02016-05-18 15:37:25 -07001416func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001417 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001418 module.features = []feature{
1419 &tidyFeature{},
1420 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001421 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001422 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001423 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001424 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001425 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001426 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001427 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001428 return module
1429}
1430
Colin Crossce75d2c2016-10-06 16:12:58 -07001431func (c *Module) Prebuilt() *android.Prebuilt {
1432 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1433 return p.prebuilt()
1434 }
1435 return nil
1436}
1437
1438func (c *Module) Name() string {
1439 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001440 if p, ok := c.linker.(interface {
1441 Name(string) string
1442 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001443 name = p.Name(name)
1444 }
1445 return name
1446}
1447
Alex Light3d673592019-01-18 14:37:31 -08001448func (c *Module) Symlinks() []string {
1449 if p, ok := c.installer.(interface {
1450 symlinkList() []string
1451 }); ok {
1452 return p.symlinkList()
1453 }
1454 return nil
1455}
1456
Jeff Gaston294356f2017-09-27 17:05:30 -07001457// orderDeps reorders dependencies into a list such that if module A depends on B, then
1458// A will precede B in the resultant list.
1459// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001460// Note that directSharedDeps should be the analogous static library for each shared lib dep
1461func 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 -07001462 // If A depends on B, then
1463 // Every list containing A will also contain B later in the list
1464 // So, after concatenating all lists, the final instance of B will have come from the same
1465 // original list as the final instance of A
1466 // So, the final instance of B will be later in the concatenation than the final A
1467 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1468 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001469 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001470 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001471 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1472 }
1473 for _, dep := range directSharedDeps {
1474 orderedAllDeps = append(orderedAllDeps, dep)
1475 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001476 }
1477
Colin Crossb6715442017-10-24 11:13:31 -07001478 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001479
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001480 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001481 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001482 // resultant list to only what the caller has chosen to include in directStaticDeps
1483 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001484
1485 return orderedAllDeps, orderedDeclaredDeps
1486}
1487
Ivan Lozano183a3212019-10-18 14:18:45 -07001488func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001489 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001490 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001491 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1492 staticDepFiles := []android.Path{}
1493 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001494 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1495 if dep.OutputFile().Valid() {
1496 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1497 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1498 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001499 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001500 sharedDepFiles := []android.Path{}
1501 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001502 if sharedDep.HasStaticVariant() {
1503 staticAnalogue := sharedDep.GetStaticVariant()
1504 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1505 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001506 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001507 }
1508
1509 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001510 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1511 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001512
1513 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001514}
1515
Roland Levillainf89cd092019-07-29 16:22:59 +01001516func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1517 test, ok := c.linker.(testPerSrc)
1518 return ok && test.isAllTestsVariation()
1519}
1520
Chris Parsons216e10a2020-07-09 17:12:52 -04001521func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001522 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001523 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001524 }); ok {
1525 return p.dataPaths()
1526 }
1527 return nil
1528}
1529
Justin Yun5f7f7e82019-11-18 19:52:14 +09001530func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1531 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1532 // "current", it will append the VNDK version to the name suffix.
1533 var vndkVersion string
1534 var nameSuffix string
1535 if c.inProduct() {
1536 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1537 nameSuffix = productSuffix
1538 } else {
1539 vndkVersion = ctx.DeviceConfig().VndkVersion()
1540 nameSuffix = vendorSuffix
1541 }
1542 if vndkVersion == "current" {
1543 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1544 }
1545 if c.Properties.VndkVersion != vndkVersion {
1546 // add version suffix only if the module is using different vndk version than the
1547 // version in product or vendor partition.
1548 nameSuffix += "." + c.Properties.VndkVersion
1549 }
1550 return nameSuffix
1551}
1552
Colin Cross635c3b02016-05-18 15:37:25 -07001553func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001554 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001555 //
1556 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1557 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1558 // module and return early, as this module does not produce an output file per se.
1559 if c.IsTestPerSrcAllTestsVariation() {
1560 c.outputFile = android.OptionalPath{}
1561 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001562 }
1563
Colin Cross56a83212020-09-15 18:30:11 -07001564 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1565 if !apexInfo.IsForPlatform() {
1566 c.hideApexVariantFromMake = true
1567 }
1568
Jooyung Han38002912019-05-16 04:01:54 +09001569 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001570
Inseob Kim64c43952019-08-26 16:52:35 +09001571 c.Properties.SubName = ""
1572
1573 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1574 c.Properties.SubName += nativeBridgeSuffix
1575 }
1576
Justin Yun5f7f7e82019-11-18 19:52:14 +09001577 _, llndk := c.linker.(*llndkStubDecorator)
1578 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1579 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1580 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1581 // added for product variant only when we have vendor and product variants with core
1582 // variant. The suffix is not added for vendor-only or product-only module.
1583 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1584 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001585 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1586 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1587 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001588 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1589 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001590 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001591 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001592 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001593 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001594 if c.SplitPerApiLevel() {
1595 c.Properties.SubName += "." + c.SdkVersion()
1596 }
Inseob Kim64c43952019-08-26 16:52:35 +09001597 }
1598
Colin Crossca860ac2016-01-04 14:34:37 -08001599 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001600 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001601 moduleContextImpl: moduleContextImpl{
1602 mod: c,
1603 },
1604 }
1605 ctx.ctx = ctx
1606
Colin Crossf18e1102017-11-16 14:33:08 -08001607 deps := c.depsToPaths(ctx)
1608 if ctx.Failed() {
1609 return
1610 }
1611
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001612 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1613 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1614 }
1615
Colin Crossca860ac2016-01-04 14:34:37 -08001616 flags := Flags{
1617 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001618 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001619 }
Colin Crossca860ac2016-01-04 14:34:37 -08001620 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001621 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001622 }
1623 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001624 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001625 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001626 if c.stl != nil {
1627 flags = c.stl.flags(ctx, flags)
1628 }
Colin Cross16b23492016-01-06 14:41:07 -08001629 if c.sanitize != nil {
1630 flags = c.sanitize.flags(ctx, flags)
1631 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001632 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001633 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001634 }
Stephen Craneba090d12017-05-09 15:44:35 -07001635 if c.lto != nil {
1636 flags = c.lto.flags(ctx, flags)
1637 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001638 if c.pgo != nil {
1639 flags = c.pgo.flags(ctx, flags)
1640 }
Colin Crossca860ac2016-01-04 14:34:37 -08001641 for _, feature := range c.features {
1642 flags = feature.flags(ctx, flags)
1643 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001644 if ctx.Failed() {
1645 return
1646 }
1647
Colin Cross4af21ed2019-11-04 09:37:55 -08001648 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1649 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1650 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001651
Colin Cross4af21ed2019-11-04 09:37:55 -08001652 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001653
1654 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001655 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001656 }
1657 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001658 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001659 }
1660
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001661 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001662 // We need access to all the flags seen by a source file.
1663 if c.sabi != nil {
1664 flags = c.sabi.flags(ctx, flags)
1665 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001666
Colin Cross4af21ed2019-11-04 09:37:55 -08001667 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001668
Colin Crossca860ac2016-01-04 14:34:37 -08001669 // Optimization to reduce size of build.ninja
1670 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001671 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1672 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1673 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1674 flags.Local.CFlags = []string{"$cflags"}
1675 flags.Local.CppFlags = []string{"$cppflags"}
1676 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001677
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001678 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001679 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001680 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001681 if ctx.Failed() {
1682 return
1683 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001684 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001685 }
1686
Colin Crossca860ac2016-01-04 14:34:37 -08001687 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001688 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001689 if ctx.Failed() {
1690 return
1691 }
Colin Cross635c3b02016-05-18 15:37:25 -07001692 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001693
1694 // If a lib is directly included in any of the APEXes, unhide the stubs
1695 // variant having the latest version gets visible to make. In addition,
1696 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1697 // force anything in the make world to link against the stubs library.
1698 // (unless it is explicitly referenced via .bootstrap suffix or the
1699 // module is marked with 'bootstrap: true').
Colin Cross56a83212020-09-15 18:30:11 -07001700 if c.HasStubsVariants() && c.AnyVariantDirectlyInAnyApex() && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001701 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001702 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001703 c.Properties.HideFromMake = false // unhide
1704 // Note: this is still non-installable
1705 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001706
1707 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1708 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
Colin Cross56a83212020-09-15 18:30:11 -07001709 if isSnapshotAware(ctx, c, apexInfo) {
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001710 i.collectHeadersForSnapshot(ctx)
1711 }
1712 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001713 }
Colin Cross5049f022015-03-18 13:28:46 -07001714
Colin Cross56a83212020-09-15 18:30:11 -07001715 if c.installable(apexInfo) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001716 c.installer.install(ctx, c.outputFile.Path())
1717 if ctx.Failed() {
1718 return
Colin Crossca860ac2016-01-04 14:34:37 -08001719 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001720 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1721 // If the module has been specifically configure to not be installed then
1722 // skip the installation as otherwise it will break when running inside make
1723 // as the output path to install will not be specified. Not all uninstallable
1724 // modules can skip installation as some are needed for resolving make side
1725 // dependencies.
1726 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001727 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001728}
1729
Colin Cross0ea8ba82019-06-06 14:33:29 -07001730func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001731 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001732 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001733 }
Colin Crossca860ac2016-01-04 14:34:37 -08001734 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001735}
1736
Colin Crossca860ac2016-01-04 14:34:37 -08001737func (c *Module) begin(ctx BaseModuleContext) {
1738 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001739 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001740 }
Colin Crossca860ac2016-01-04 14:34:37 -08001741 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001742 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001743 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001744 if c.stl != nil {
1745 c.stl.begin(ctx)
1746 }
Colin Cross16b23492016-01-06 14:41:07 -08001747 if c.sanitize != nil {
1748 c.sanitize.begin(ctx)
1749 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001750 if c.coverage != nil {
1751 c.coverage.begin(ctx)
1752 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001753 if c.sabi != nil {
1754 c.sabi.begin(ctx)
1755 }
Justin Yun8effde42017-06-23 19:24:43 +09001756 if c.vndkdep != nil {
1757 c.vndkdep.begin(ctx)
1758 }
Stephen Craneba090d12017-05-09 15:44:35 -07001759 if c.lto != nil {
1760 c.lto.begin(ctx)
1761 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001762 if c.pgo != nil {
1763 c.pgo.begin(ctx)
1764 }
Colin Crossca860ac2016-01-04 14:34:37 -08001765 for _, feature := range c.features {
1766 feature.begin(ctx)
1767 }
Dan Albert92fe7402020-07-15 13:33:30 -07001768 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001769 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001770 if err != nil {
1771 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001772 c.Properties.Sdk_version = nil
1773 } else {
1774 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001775 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001776 }
Colin Crossca860ac2016-01-04 14:34:37 -08001777}
1778
Colin Cross37047f12016-12-13 17:06:13 -08001779func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001780 deps := Deps{}
1781
1782 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001783 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001784 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001785 // Add the PGO dependency (the clang_rt.profile runtime library), which
1786 // sometimes depends on symbols from libgcc, before libgcc gets added
1787 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001788 if c.pgo != nil {
1789 deps = c.pgo.deps(ctx, deps)
1790 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001791 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001792 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001793 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001794 if c.stl != nil {
1795 deps = c.stl.deps(ctx, deps)
1796 }
Colin Cross16b23492016-01-06 14:41:07 -08001797 if c.sanitize != nil {
1798 deps = c.sanitize.deps(ctx, deps)
1799 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001800 if c.coverage != nil {
1801 deps = c.coverage.deps(ctx, deps)
1802 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001803 if c.sabi != nil {
1804 deps = c.sabi.deps(ctx, deps)
1805 }
Justin Yun8effde42017-06-23 19:24:43 +09001806 if c.vndkdep != nil {
1807 deps = c.vndkdep.deps(ctx, deps)
1808 }
Stephen Craneba090d12017-05-09 15:44:35 -07001809 if c.lto != nil {
1810 deps = c.lto.deps(ctx, deps)
1811 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001812 for _, feature := range c.features {
1813 deps = feature.deps(ctx, deps)
1814 }
1815
Colin Crossb6715442017-10-24 11:13:31 -07001816 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1817 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1818 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1819 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1820 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1821 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001822 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001823
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001824 for _, lib := range deps.ReexportSharedLibHeaders {
1825 if !inList(lib, deps.SharedLibs) {
1826 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1827 }
1828 }
1829
1830 for _, lib := range deps.ReexportStaticLibHeaders {
1831 if !inList(lib, deps.StaticLibs) {
1832 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1833 }
1834 }
1835
Colin Cross5950f382016-12-13 12:50:57 -08001836 for _, lib := range deps.ReexportHeaderLibHeaders {
1837 if !inList(lib, deps.HeaderLibs) {
1838 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1839 }
1840 }
1841
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001842 for _, gen := range deps.ReexportGeneratedHeaders {
1843 if !inList(gen, deps.GeneratedHeaders) {
1844 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1845 }
1846 }
1847
Colin Crossc99deeb2016-04-11 15:06:20 -07001848 return deps
1849}
1850
Dan Albert7e9d2952016-08-04 13:02:36 -07001851func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001852 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001853 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001854 moduleContextImpl: moduleContextImpl{
1855 mod: c,
1856 },
1857 }
1858 ctx.ctx = ctx
1859
Colin Crossca860ac2016-01-04 14:34:37 -08001860 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001861}
1862
Jiyong Park7ed9de32018-10-15 22:25:07 +09001863// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001864func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001865 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1866 version := name[sharp+1:]
1867 libname := name[:sharp]
1868 return libname, version
1869 }
1870 return name, ""
1871}
1872
Dan Albert92fe7402020-07-15 13:33:30 -07001873func GetCrtVariations(ctx android.BottomUpMutatorContext,
1874 m LinkableInterface) []blueprint.Variation {
1875 if ctx.Os() != android.Android {
1876 return nil
1877 }
1878 if m.UseSdk() {
1879 return []blueprint.Variation{
1880 {Mutator: "sdk", Variation: "sdk"},
1881 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1882 }
1883 }
1884 return []blueprint.Variation{
1885 {Mutator: "sdk", Variation: ""},
1886 }
1887}
1888
Colin Crosse7257d22020-09-24 09:56:18 -07001889func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext,
1890 variations []blueprint.Variation, depTag libraryDependencyTag, name, version string, far bool) {
1891
1892 variations = append([]blueprint.Variation(nil), variations...)
1893
Colin Cross3146c5c2020-09-30 15:34:40 -07001894 if version != "" && CanBeOrLinkAgainstVersionVariants(c) {
Colin Crosse7257d22020-09-24 09:56:18 -07001895 // Version is explicitly specified. i.e. libFoo#30
1896 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1897 depTag.explicitlyVersioned = true
1898 }
1899 var deps []blueprint.Module
1900 if far {
1901 deps = ctx.AddFarVariationDependencies(variations, depTag, name)
1902 } else {
1903 deps = ctx.AddVariationDependencies(variations, depTag, name)
1904 }
1905
1906 // If the version is not specified, add dependency to all stubs libraries.
1907 // The stubs library will be used when the depending module is built for APEX and
1908 // the dependent module is not in the same APEX.
Colin Cross3146c5c2020-09-30 15:34:40 -07001909 if version == "" && CanBeOrLinkAgainstVersionVariants(c) {
Colin Crosse7257d22020-09-24 09:56:18 -07001910 if dep, ok := deps[0].(*Module); ok {
1911 for _, ver := range dep.AllStubsVersions() {
1912 // Note that depTag.ExplicitlyVersioned is false in this case.
1913 versionVariations := append(variations,
1914 blueprint.Variation{Mutator: "version", Variation: ver})
1915 if far {
1916 ctx.AddFarVariationDependencies(versionVariations, depTag, name)
1917 } else {
1918 ctx.AddVariationDependencies(versionVariations, depTag, name)
1919 }
1920 }
1921 }
1922 }
1923}
1924
Colin Cross1e676be2016-10-12 14:38:15 -07001925func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001926 if !c.Enabled() {
1927 return
1928 }
1929
Colin Cross37047f12016-12-13 17:06:13 -08001930 ctx := &depsContext{
1931 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001932 moduleContextImpl: moduleContextImpl{
1933 mod: c,
1934 },
1935 }
1936 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001937
Colin Crossc99deeb2016-04-11 15:06:20 -07001938 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001939
Yo Chiang219968c2020-09-22 18:45:04 +08001940 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
1941
Dan Albert914449f2016-06-17 16:45:24 -07001942 variantNdkLibs := []string{}
1943 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001944 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001945 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001946 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001947 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001948 // 1. Name of an NDK library that refers to a prebuilt module.
1949 // For each of these, it adds the name of the prebuilt module (which will be in
1950 // prebuilts/ndk) to the list of nonvariant libs.
1951 // 2. Name of an NDK library that refers to an ndk_library module.
1952 // For each of these, it adds the name of the ndk_library module to the list of
1953 // variant libs.
1954 // 3. Anything else (so anything that isn't an NDK library).
1955 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001956 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001957 // The caller can then know to add the variantLibs dependencies differently from the
1958 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001959
Inseob Kim9516ee92019-05-09 10:56:13 +09001960 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001961 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1962
1963 rewriteVendorLibs := func(lib string) string {
1964 if isLlndkLibrary(lib, ctx.Config()) {
1965 return lib + llndkLibrarySuffix
1966 }
1967
1968 // only modules with BOARD_VNDK_VERSION uses snapshot.
1969 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1970 return lib
1971 }
1972
1973 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1974 return snapshot
1975 }
1976
1977 return lib
1978 }
1979
1980 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001981 variantLibs = []string{}
1982 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001983 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001984 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001985 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001986 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1987 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001988 } else if ctx.useVndk() {
1989 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001990 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001991 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001992 if actx.OtherModuleExists(vendorPublicLib) {
1993 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1994 } else {
1995 // This can happen if vendor_public_library module is defined in a
1996 // namespace that isn't visible to the current module. In that case,
1997 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001998 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001999 }
Dan Albert914449f2016-06-17 16:45:24 -07002000 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002001 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07002002 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07002003 }
2004 }
Dan Albert914449f2016-06-17 16:45:24 -07002005 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07002006 }
2007
Inseob Kimeec88e12020-01-22 11:11:29 +09002008 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
2009 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
2010 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
2011 if ctx.useVndk() {
2012 for idx, lib := range deps.RuntimeLibs {
2013 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
2014 }
2015 }
Dan Willemsen72d39932016-07-08 23:23:48 -07002016 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002017
Jiyong Park7e636d02019-01-28 16:16:54 +09002018 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09002019 if c.linker != nil {
2020 if library, ok := c.linker.(*libraryDecorator); ok {
2021 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09002022 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09002023 }
2024 }
Colin Crossd48fe732020-09-23 20:37:24 -07002025 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
2026 if library.buildStubs() {
2027 buildStubs = true
2028 }
2029 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002030 }
2031
Inseob Kimeec88e12020-01-22 11:11:29 +09002032 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
2033 // only modules with BOARD_VNDK_VERSION uses snapshot.
2034 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
2035 return lib
2036 }
2037
2038 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
2039 return snapshot
2040 }
2041
2042 return lib
2043 }
2044
2045 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08002046 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002047 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08002048 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002049 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08002050 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002051
2052 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
2053
Jiyong Park7e636d02019-01-28 16:16:54 +09002054 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08002055 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07002056 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09002057 } else {
2058 actx.AddVariationDependencies(nil, depTag, lib)
2059 }
2060 }
2061
2062 if buildStubs {
2063 // Stubs lib does not have dependency to other static/shared libraries.
2064 // Don't proceed.
2065 return
Colin Cross32ec36c2016-12-15 07:39:51 -08002066 }
Colin Cross5950f382016-12-13 12:50:57 -08002067
Inseob Kimc0907f12019-02-08 21:00:45 +09002068 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09002069 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09002070
Jiyong Park5d1598f2019-02-25 22:14:17 +09002071 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002072 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09002073 if impl, ok := syspropImplLibraries[lib]; ok {
2074 lib = impl
2075 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002076
2077 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
2078
Jiyong Park5d1598f2019-02-25 22:14:17 +09002079 actx.AddVariationDependencies([]blueprint.Variation{
2080 {Mutator: "link", Variation: "static"},
2081 }, depTag, lib)
2082 }
2083
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002084 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002085 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002086 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002087 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002088 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002089
2090 if impl, ok := syspropImplLibraries[lib]; ok {
2091 lib = impl
2092 }
2093
Inseob Kimeec88e12020-01-22 11:11:29 +09002094 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
2095
Dan Willemsen59339a22018-07-22 21:18:45 -07002096 actx.AddVariationDependencies([]blueprint.Variation{
2097 {Mutator: "link", Variation: "static"},
2098 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002099 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002100
Jooyung Han75568392020-03-20 04:29:24 +09002101 // staticUnwinderDep is treated as staticDep for Q apexes
2102 // so that native libraries/binaries are linked with static unwinder
2103 // because Q libc doesn't have unwinder APIs
2104 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07002105 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002106 actx.AddVariationDependencies([]blueprint.Variation{
2107 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002108 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002109 }
2110
Inseob Kimeec88e12020-01-22 11:11:29 +09002111 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002112 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09002113 actx.AddVariationDependencies([]blueprint.Variation{
2114 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002115 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09002116 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002117
Jiyong Park7ed9de32018-10-15 22:25:07 +09002118 // shared lib names without the #version suffix
2119 var sharedLibNames []string
2120
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002121 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002122 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002123 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002124 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002125 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002126
2127 if impl, ok := syspropImplLibraries[lib]; ok {
2128 lib = impl
2129 }
2130
Jiyong Park73c54ee2019-10-22 20:31:18 +09002131 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002132 sharedLibNames = append(sharedLibNames, name)
2133
Colin Crosse7257d22020-09-24 09:56:18 -07002134 variations := []blueprint.Variation{
2135 {Mutator: "link", Variation: "shared"},
2136 }
2137 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, name, version, false)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002138 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002139
Jiyong Park7ed9de32018-10-15 22:25:07 +09002140 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002141 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002142 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2143 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2144 // linking against both the stubs lib and the non-stubs lib at the same time.
2145 continue
2146 }
Colin Cross6e511a92020-07-27 21:26:48 -07002147 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
Colin Crosse7257d22020-09-24 09:56:18 -07002148 variations := []blueprint.Variation{
2149 {Mutator: "link", Variation: "shared"},
2150 }
2151 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, lib, "", false)
Jiyong Park7ed9de32018-10-15 22:25:07 +09002152 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002153
Dan Willemsen59339a22018-07-22 21:18:45 -07002154 actx.AddVariationDependencies([]blueprint.Variation{
2155 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002156 }, dataLibDepTag, deps.DataLibs...)
2157
2158 actx.AddVariationDependencies([]blueprint.Variation{
2159 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002160 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002161
Colin Cross68861832016-07-08 10:41:41 -07002162 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002163
2164 for _, gen := range deps.GeneratedHeaders {
2165 depTag := genHeaderDepTag
2166 if inList(gen, deps.ReexportGeneratedHeaders) {
2167 depTag = genHeaderExportDepTag
2168 }
2169 actx.AddDependency(c, depTag, gen)
2170 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002171
Colin Cross42d48b72018-08-29 14:10:52 -07002172 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002173
Inseob Kim1042d292020-06-01 23:23:05 +09002174 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2175
Dan Albert92fe7402020-07-15 13:33:30 -07002176 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07002177 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002178 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2179 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002180 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002181 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002182 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2183 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002184 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002185 if deps.LinkerFlagsFile != "" {
2186 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2187 }
2188 if deps.DynamicLinker != "" {
2189 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002190 }
Dan Albert914449f2016-06-17 16:45:24 -07002191
2192 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002193
2194 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002195 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002196 {Mutator: "ndk_api", Variation: version},
2197 {Mutator: "link", Variation: "shared"},
2198 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002199
2200 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002201 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002202 {Mutator: "ndk_api", Variation: version},
2203 {Mutator: "link", Variation: "shared"},
2204 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002205
2206 if vndkdep := c.vndkdep; vndkdep != nil {
2207 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002208 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002209 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002210 {Mutator: "link", Variation: "shared"},
2211 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002212 }
2213 }
Colin Cross6362e272015-10-29 15:25:03 -07002214}
Colin Cross21b9a242015-03-24 14:15:58 -07002215
Colin Crosse40b4ea2018-10-02 22:25:58 -07002216func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002217 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2218 c.beginMutator(ctx)
2219 }
2220}
2221
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002222// Whether a module can link to another module, taking into
2223// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002224func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2225 tag blueprint.DependencyTag) {
2226
2227 switch t := tag.(type) {
2228 case dependencyTag:
2229 if t != vndkExtDepTag {
2230 return
2231 }
2232 case libraryDependencyTag:
2233 default:
2234 return
2235 }
2236
Ivan Lozano52767be2019-10-18 14:49:46 -07002237 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002238 // Host code is not restricted
2239 return
2240 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002241
2242 // VNDK is cc.Module supported only for now.
2243 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002244 // Though vendor code is limited by the vendor mutator,
2245 // each vendor-available module needs to check
2246 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002247 if ccTo, ok := to.(*Module); ok {
2248 if ccFrom.vndkdep != nil {
2249 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2250 }
2251 } else {
2252 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002253 }
2254 return
2255 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002256 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002257 // Platform code can link to anything
2258 return
2259 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002260 if from.InRamdisk() {
2261 // Ramdisk code is not NDK
2262 return
2263 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002264 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002265 // Recovery code is not NDK
2266 return
2267 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002268 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002269 // These are always allowed
2270 return
2271 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002272 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002273 // These are allowed, but they don't set sdk_version
2274 return
2275 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002276 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002277 // These aren't real libraries, but are the stub shared libraries that are included in
2278 // the NDK.
2279 return
2280 }
Logan Chien834b9a62019-01-14 15:39:03 +08002281
Ivan Lozano52767be2019-10-18 14:49:46 -07002282 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002283 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2284 // to link to libc++ (non-NDK and without sdk_version).
2285 return
2286 }
2287
Ivan Lozano52767be2019-10-18 14:49:46 -07002288 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002289 // NDK code linking to platform code is never okay.
2290 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002291 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002292 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002293 }
2294
2295 // At this point we know we have two NDK libraries, but we need to
2296 // check that we're not linking against anything built against a higher
2297 // API level, as it is only valid to link against older or equivalent
2298 // APIs.
2299
Inseob Kim01a28722018-04-11 09:48:45 +09002300 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002301 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002302 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002303 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002304 // Current can't be linked against by anything else.
2305 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002306 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002307 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002308 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002309 if err != nil {
2310 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002311 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002312 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002313 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002314 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002315 if err != nil {
2316 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002317 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002318 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002319 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002320
Inseob Kim01a28722018-04-11 09:48:45 +09002321 if toApi > fromApi {
2322 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002323 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002324 }
2325 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002326 }
Dan Albert202fe492017-12-15 13:56:59 -08002327
2328 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002329 fromStl := from.SelectedStl()
2330 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002331 if fromStl == "" || toStl == "" {
2332 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002333 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002334 // We can be permissive with the system "STL" since it is only the C++
2335 // ABI layer, but in the future we should make sure that everyone is
2336 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002337 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002338 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002339 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2340 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002341 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002342}
2343
Jiyong Park5fb8c102018-04-09 12:03:06 +09002344// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002345// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2346// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002347// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002348func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2349 check := func(child, parent android.Module) bool {
2350 to, ok := child.(*Module)
2351 if !ok {
2352 // follow thru cc.Defaults, etc.
2353 return true
2354 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002355
Jooyung Hana70f0672019-01-18 15:20:43 +09002356 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2357 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002358 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002359
2360 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002361 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002362 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002363 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002364
Jooyung Han0302a842019-10-30 18:43:49 +09002365 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002366 return false
2367 }
2368
2369 var stringPath []string
2370 for _, m := range ctx.GetWalkPath() {
2371 stringPath = append(stringPath, m.Name())
2372 }
2373 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2374 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2375 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2376 return false
2377 }
2378 if module, ok := ctx.Module().(*Module); ok {
2379 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002380 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002381 ctx.WalkDeps(check)
2382 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002383 }
2384 }
2385}
2386
Colin Crossc99deeb2016-04-11 15:06:20 -07002387// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002388func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002389 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002390
Ivan Lozano183a3212019-10-18 14:18:45 -07002391 directStaticDeps := []LinkableInterface{}
2392 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002393
Inseob Kim69378442019-06-03 19:10:47 +09002394 reexportExporter := func(exporter exportedFlagsProducer) {
2395 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2396 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2397 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2398 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002399 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002400 }
2401
Jooyung Hande34d232020-07-23 13:04:15 +09002402 // For the dependency from platform to apex, use the latest stubs
2403 c.apexSdkVersion = android.FutureApiLevel
Colin Cross56a83212020-09-15 18:30:11 -07002404 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
2405 if !apexInfo.IsForPlatform() {
2406 c.apexSdkVersion = apexInfo.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002407 }
2408
2409 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2410 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2411 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2412 // (b/144430859)
2413 c.apexSdkVersion = android.FutureApiLevel
2414 }
2415
Colin Crossd11fcda2017-10-23 17:59:01 -07002416 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002417 depName := ctx.OtherModuleName(dep)
2418 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002419
Ivan Lozano52767be2019-10-18 14:49:46 -07002420 ccDep, ok := dep.(LinkableInterface)
2421 if !ok {
2422
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002423 // handling for a few module types that aren't cc Module but that are also supported
2424 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002425 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002426 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002427 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2428 genRule.GeneratedSourceFiles()...)
2429 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002430 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002431 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002432 // Support exported headers from a generated_sources dependency
2433 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002434 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002435 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002436 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002437 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002438 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002439 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002440 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002441 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002442 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2443 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002444 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002445 // 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 +09002446 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002447
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002448 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002449 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002450 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002451 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002452 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002453 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002454 files := genRule.GeneratedSourceFiles()
2455 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002456 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002457 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002458 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 -07002459 }
2460 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002461 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002462 }
Colin Crossca860ac2016-01-04 14:34:37 -08002463 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002464 return
2465 }
2466
Colin Crossfe17f6f2019-03-28 19:30:56 -07002467 if depTag == android.ProtoPluginDepTag {
2468 return
2469 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002470 if depTag == llndkImplDep {
2471 return
2472 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002473
Colin Crossd11fcda2017-10-23 17:59:01 -07002474 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002475 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2476 return
2477 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002478 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002479 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2480 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002481 return
2482 }
2483
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002484 // re-exporting flags
2485 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002486 // reusing objects only make sense for cc.Modules.
2487 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002488 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002489 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002490 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002491 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002492 return
2493 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002494 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002495
Jiyong Parke4bb9862019-02-01 00:31:10 +09002496 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002497 // staticVariants are a cc.Module specific concept.
2498 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002499 c.staticVariant = ccDep
2500 return
2501 }
2502 }
2503
Colin Cross6e511a92020-07-27 21:26:48 -07002504 checkLinkType(ctx, c, ccDep, depTag)
2505
2506 linkFile := ccDep.OutputFile()
2507
2508 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2509 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002510 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002511 return
2512 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002513
Colin Cross6e511a92020-07-27 21:26:48 -07002514 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002515 depIsStubs := ccDep.BuildStubs()
Colin Cross3146c5c2020-09-30 15:34:40 -07002516 depHasStubs := CanBeOrLinkAgainstVersionVariants(c) && ccDep.HasStubsVariants()
Colin Cross56a83212020-09-15 18:30:11 -07002517 depInSameApexes := android.DirectlyInAllApexes(apexInfo, depName)
2518 depInPlatform := !dep.(android.ApexModule).AnyVariantDirectlyInAnyApex()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002519
2520 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002521 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002522 // Always respect dependency to the versioned stubs (i.e. libX#10)
2523 useThisDep = true
2524 } else if !depHasStubs {
2525 // Use non-stub variant if that is the only choice
2526 // (i.e. depending on a lib without stubs.version property)
2527 useThisDep = true
Colin Cross56a83212020-09-15 18:30:11 -07002528 } else if apexInfo.IsForPlatform() {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002529 // If not building for APEX, use stubs only when it is from
2530 // an APEX (and not from platform)
2531 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002532 if c.bootstrap() {
2533 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002534 // always link to non-stub variant
2535 useThisDep = !depIsStubs
2536 }
Colin Cross56a83212020-09-15 18:30:11 -07002537 // Another exception: if this module is bundled with an APEX, then
2538 // it is linked with the non-stub variant of a module in the APEX
2539 // as if this is part of the APEX.
2540 testFor := ctx.Provider(android.ApexTestForInfoProvider).(android.ApexTestForInfo)
2541 for _, apexContents := range testFor.ApexContents {
2542 if apexContents.DirectlyInApex(depName) {
Jiyong Park62304bb2020-04-13 16:19:48 +09002543 useThisDep = !depIsStubs
2544 break
2545 }
2546 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002547 } else {
Colin Crossaede88c2020-08-11 12:17:01 -07002548 // If building for APEX, use stubs when the parent is in any APEX that
2549 // the child is not in.
2550 useThisDep = (depInSameApexes != depIsStubs)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002551 }
2552
Jooyung Han03b51852020-02-26 22:45:42 +09002553 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002554 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Colin Cross7812fd32020-09-25 12:35:10 -07002555 versionToUse, err := c.ChooseSdkVersion(ctx, ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002556 if err != nil {
2557 ctx.OtherModuleErrorf(dep, err.Error())
2558 return
2559 }
2560 if versionToUse != ccDep.StubsVersion() {
2561 useThisDep = false
2562 }
2563 }
2564
Jiyong Park25fc6a92018-11-18 18:02:45 +09002565 if !useThisDep {
2566 return // stop processing this dep
2567 }
2568 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002569 if c.UseVndk() {
2570 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2571 // by default, use current version of LLNDK
2572 versionToUse := ""
Colin Crossd1f898e2020-08-18 18:35:15 -07002573 versions := m.AllStubsVersions()
Colin Cross56a83212020-09-15 18:30:11 -07002574 if apexInfo.ApexVariationName != "" && len(versions) > 0 {
Jooyung Han61b66e92020-03-21 14:21:46 +00002575 // if this is for use_vendor apex && dep has stubsVersions
2576 // apply the same rule of apex sdk enforcement to choose right version
2577 var err error
Colin Cross7812fd32020-09-25 12:35:10 -07002578 versionToUse, err = c.ChooseSdkVersion(ctx, versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002579 if err != nil {
2580 ctx.OtherModuleErrorf(dep, err.Error())
2581 return
2582 }
2583 }
2584 if versionToUse != ccDep.StubsVersion() {
2585 return
2586 }
2587 }
2588 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002589
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002590 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2591
Ivan Lozano52767be2019-10-18 14:49:46 -07002592 // Exporting flags only makes sense for cc.Modules
2593 if _, ok := ccDep.(*Module); ok {
2594 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002595 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002596 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002597 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002598
Colin Cross6e511a92020-07-27 21:26:48 -07002599 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002600 reexportExporter(i)
2601 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2602 // Re-exported shared library headers must be included as well since they can help us with type information
2603 // about template instantiations (instantiated from their headers).
2604 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2605 // scripts.
2606 c.sabi.Properties.ReexportedIncludes = append(
2607 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2608 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002609 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002610 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002611
Colin Cross6e511a92020-07-27 21:26:48 -07002612 var ptr *android.Paths
2613 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002614
Colin Cross6e511a92020-07-27 21:26:48 -07002615 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002616
Colin Cross6e511a92020-07-27 21:26:48 -07002617 switch {
2618 case libDepTag.header():
2619 // nothing
2620 case libDepTag.shared():
2621 ptr = &depPaths.SharedLibs
2622 switch libDepTag.Order {
2623 case earlyLibraryDependency:
2624 ptr = &depPaths.EarlySharedLibs
2625 depPtr = &depPaths.EarlySharedLibsDeps
2626 case normalLibraryDependency:
2627 ptr = &depPaths.SharedLibs
2628 depPtr = &depPaths.SharedLibsDeps
2629 directSharedDeps = append(directSharedDeps, ccDep)
2630 case lateLibraryDependency:
2631 ptr = &depPaths.LateSharedLibs
2632 depPtr = &depPaths.LateSharedLibsDeps
2633 default:
2634 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002635 }
Colin Cross6e511a92020-07-27 21:26:48 -07002636 depFile = ccDep.Toc()
2637 case libDepTag.static():
2638 if libDepTag.wholeStatic {
2639 ptr = &depPaths.WholeStaticLibs
2640 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2641 ctx.ModuleErrorf("module %q not a static library", depName)
2642 return
Inseob Kim752edec2020-03-14 01:30:34 +09002643 }
2644
Colin Cross6e511a92020-07-27 21:26:48 -07002645 // Because the static library objects are included, this only makes sense
2646 // in the context of proper cc.Modules.
2647 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2648 staticLib := ccWholeStaticLib.linker.(libraryInterface)
Colin Crosse4f6eba2020-09-22 18:11:25 -07002649 if objs := staticLib.objs(); len(objs.objFiles) > 0 {
2650 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(objs)
Colin Cross6e511a92020-07-27 21:26:48 -07002651 } else {
Colin Crosse4f6eba2020-09-22 18:11:25 -07002652 // This case normally catches prebuilt static
2653 // libraries, but it can also occur when
2654 // AllowMissingDependencies is on and the
2655 // dependencies has no sources of its own
2656 // but has a whole_static_libs dependency
2657 // on a missing library. We want to depend
2658 // on the .a file so that there is something
2659 // in the dependency tree that contains the
2660 // error rule for the missing transitive
2661 // dependency.
2662 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07002663 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002664 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002665 ctx.ModuleErrorf(
2666 "non-cc.Modules cannot be included as whole static libraries.", depName)
2667 return
2668 }
2669
2670 } else {
2671 switch libDepTag.Order {
2672 case earlyLibraryDependency:
2673 panic(fmt.Errorf("early static libs not suppported"))
2674 case normalLibraryDependency:
2675 // static dependencies will be handled separately so they can be ordered
2676 // using transitive dependencies.
2677 ptr = nil
2678 directStaticDeps = append(directStaticDeps, ccDep)
2679 case lateLibraryDependency:
2680 ptr = &depPaths.LateStaticLibs
2681 default:
2682 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002683 }
2684 }
2685 }
2686
Colin Cross6e511a92020-07-27 21:26:48 -07002687 if libDepTag.static() && !libDepTag.wholeStatic {
2688 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2689 ctx.ModuleErrorf("module %q not a static library", depName)
2690 return
2691 }
Logan Chien43d34c32017-12-20 01:17:32 +08002692
Colin Cross6e511a92020-07-27 21:26:48 -07002693 // When combining coverage files for shared libraries and executables, coverage files
2694 // in static libraries act as if they were whole static libraries. The same goes for
2695 // source based Abi dump files.
2696 if c, ok := ccDep.(*Module); ok {
2697 staticLib := c.linker.(libraryInterface)
2698 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2699 staticLib.objs().coverageFiles...)
2700 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2701 staticLib.objs().sAbiDumpFiles...)
2702 } else if c, ok := ccDep.(LinkableInterface); ok {
2703 // Handle non-CC modules here
2704 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2705 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002706 }
2707 }
2708
Colin Cross6e511a92020-07-27 21:26:48 -07002709 if ptr != nil {
2710 if !linkFile.Valid() {
2711 if !ctx.Config().AllowMissingDependencies() {
2712 ctx.ModuleErrorf("module %q missing output file", depName)
2713 } else {
2714 ctx.AddMissingDependencies([]string{depName})
2715 }
2716 return
2717 }
2718 *ptr = append(*ptr, linkFile.Path())
2719 }
2720
2721 if depPtr != nil {
2722 dep := depFile
2723 if !dep.Valid() {
2724 dep = linkFile
2725 }
2726 *depPtr = append(*depPtr, dep.Path())
2727 }
2728
2729 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2730 switch {
2731 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002732 c.Properties.AndroidMkHeaderLibs = append(
2733 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002734 case libDepTag.shared():
2735 if ccDep.CcLibrary() {
Colin Cross56a83212020-09-15 18:30:11 -07002736 if ccDep.BuildStubs() && dep.(android.ApexModule).InAnyApex() {
Colin Cross6e511a92020-07-27 21:26:48 -07002737 // Add the dependency to the APEX(es) providing the library so that
2738 // m <module> can trigger building the APEXes as well.
Colin Cross56a83212020-09-15 18:30:11 -07002739 depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
2740 for _, an := range depApexInfo.InApexes {
Colin Cross6e511a92020-07-27 21:26:48 -07002741 c.Properties.ApexesProvidingSharedLibs = append(
2742 c.Properties.ApexesProvidingSharedLibs, an)
2743 }
2744 }
2745 }
2746
2747 // Note: the order of libs in this list is not important because
2748 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002749 c.Properties.AndroidMkSharedLibs = append(
2750 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002751 // Record baseLibName for snapshots.
2752 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2753 case libDepTag.static():
2754 if libDepTag.wholeStatic {
2755 c.Properties.AndroidMkWholeStaticLibs = append(
2756 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2757 } else {
2758 c.Properties.AndroidMkStaticLibs = append(
2759 c.Properties.AndroidMkStaticLibs, makeLibName)
2760 }
2761 }
2762 } else {
2763 switch depTag {
2764 case runtimeDepTag:
2765 c.Properties.AndroidMkRuntimeLibs = append(
2766 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2767 // Record baseLibName for snapshots.
2768 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2769 case objDepTag:
2770 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2771 case CrtBeginDepTag:
2772 depPaths.CrtBegin = linkFile
2773 case CrtEndDepTag:
2774 depPaths.CrtEnd = linkFile
2775 case dynamicLinkerDepTag:
2776 depPaths.DynamicLinker = linkFile
2777 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002778 }
Colin Crossca860ac2016-01-04 14:34:37 -08002779 })
2780
Jeff Gaston294356f2017-09-27 17:05:30 -07002781 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002782 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002783
Colin Crossdd84e052017-05-17 13:44:16 -07002784 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002785 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002786 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2787 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002788 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002789 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2790 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002791 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002792 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002793 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002794
2795 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002796 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002797 }
Colin Crossdd84e052017-05-17 13:44:16 -07002798
Colin Crossca860ac2016-01-04 14:34:37 -08002799 return depPaths
2800}
2801
Colin Cross6e511a92020-07-27 21:26:48 -07002802// baseLibName trims known prefixes and suffixes
2803func baseLibName(depName string) string {
2804 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2805 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2806 libName = strings.TrimPrefix(libName, "prebuilt_")
2807 return libName
2808}
2809
2810func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2811 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2812 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2813
2814 libName := baseLibName(depName)
2815 isLLndk := isLlndkLibrary(libName, ctx.Config())
2816 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2817 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2818
2819 if c, ok := ccDep.(*Module); ok {
2820 // Use base module name for snapshots when exporting to Makefile.
2821 if c.isSnapshotPrebuilt() {
2822 baseName := c.BaseModuleName()
2823
2824 if c.IsVndk() {
2825 return baseName + ".vendor"
2826 }
2827
2828 if vendorSuffixModules[baseName] {
2829 return baseName + ".vendor"
2830 } else {
2831 return baseName
2832 }
2833 }
2834 }
2835
2836 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2837 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2838 // core module instead.
2839 return libName
2840 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2841 // The vendor module in Make will have been renamed to not conflict with the core
2842 // module, so update the dependency name here accordingly.
2843 return libName + c.getNameSuffixWithVndkVersion(ctx)
2844 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2845 return libName + vendorPublicLibrarySuffix
2846 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2847 return libName + ramdiskSuffix
2848 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2849 return libName + recoverySuffix
2850 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2851 return libName + nativeBridgeSuffix
2852 } else {
2853 return libName
2854 }
2855}
2856
Colin Crossca860ac2016-01-04 14:34:37 -08002857func (c *Module) InstallInData() bool {
2858 if c.installer == nil {
2859 return false
2860 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002861 return c.installer.inData()
2862}
2863
2864func (c *Module) InstallInSanitizerDir() bool {
2865 if c.installer == nil {
2866 return false
2867 }
2868 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002869 return true
2870 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002871 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002872}
2873
Yifan Hong1b3348d2020-01-21 15:53:22 -08002874func (c *Module) InstallInRamdisk() bool {
2875 return c.InRamdisk()
2876}
2877
Jiyong Parkf9332f12018-02-01 00:54:12 +09002878func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002879 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002880}
2881
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002882func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002883 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002884 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002885 return
2886 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002887 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002888}
2889
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002890func (c *Module) HostToolPath() android.OptionalPath {
2891 if c.installer == nil {
2892 return android.OptionalPath{}
2893 }
2894 return c.installer.hostToolPath()
2895}
2896
Nan Zhangd4e641b2017-07-12 12:55:28 -07002897func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2898 return c.outputFile
2899}
2900
Colin Cross41955e82019-05-29 14:40:35 -07002901func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2902 switch tag {
2903 case "":
2904 if c.outputFile.Valid() {
2905 return android.Paths{c.outputFile.Path()}, nil
2906 }
2907 return android.Paths{}, nil
2908 default:
2909 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002910 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002911}
2912
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002913func (c *Module) static() bool {
2914 if static, ok := c.linker.(interface {
2915 static() bool
2916 }); ok {
2917 return static.static()
2918 }
2919 return false
2920}
2921
Jiyong Park379de2f2018-12-19 02:47:14 +09002922func (c *Module) staticBinary() bool {
2923 if static, ok := c.linker.(interface {
2924 staticBinary() bool
2925 }); ok {
2926 return static.staticBinary()
2927 }
2928 return false
2929}
2930
Jiyong Park1d1119f2019-07-29 21:27:18 +09002931func (c *Module) header() bool {
2932 if h, ok := c.linker.(interface {
2933 header() bool
2934 }); ok {
2935 return h.header()
2936 }
2937 return false
2938}
2939
Inseob Kim7f283f42020-06-01 21:53:49 +09002940func (c *Module) binary() bool {
2941 if b, ok := c.linker.(interface {
2942 binary() bool
2943 }); ok {
2944 return b.binary()
2945 }
2946 return false
2947}
2948
Inseob Kim1042d292020-06-01 23:23:05 +09002949func (c *Module) object() bool {
2950 if o, ok := c.linker.(interface {
2951 object() bool
2952 }); ok {
2953 return o.object()
2954 }
2955 return false
2956}
2957
Jooyung Han38002912019-05-16 04:01:54 +09002958func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002959 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002960 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2961 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002962 return "native:vndk"
2963 }
Jooyung Han38002912019-05-16 04:01:54 +09002964 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002965 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002966 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002967 if Bool(c.VendorProperties.Vendor_available) {
2968 return "native:vndk"
2969 }
2970 return "native:vndk_private"
2971 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002972 if c.inProduct() {
2973 return "native:product"
2974 }
Jooyung Han38002912019-05-16 04:01:54 +09002975 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002976 } else if c.InRamdisk() {
2977 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002978 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002979 return "native:recovery"
2980 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2981 return "native:ndk:none:none"
2982 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2983 //family, link := getNdkStlFamilyAndLinkType(c)
2984 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002985 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002986 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002987 } else {
2988 return "native:platform"
2989 }
2990}
2991
Jiyong Park9d452992018-10-03 00:38:19 +09002992// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002993// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002994func (c *Module) IsInstallableToApex() bool {
2995 if shared, ok := c.linker.(interface {
2996 shared() bool
2997 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002998 // Stub libs and prebuilt libs in a versioned SDK are not
2999 // installable to APEX even though they are shared libs.
3000 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01003001 } else if _, ok := c.linker.(testPerSrc); ok {
3002 return true
Jiyong Park9d452992018-10-03 00:38:19 +09003003 }
3004 return false
3005}
3006
Jiyong Parka90ca002019-10-07 15:47:24 +09003007func (c *Module) AvailableFor(what string) bool {
3008 if linker, ok := c.linker.(interface {
3009 availableFor(string) bool
3010 }); ok {
3011 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
3012 } else {
3013 return c.ApexModuleBase.AvailableFor(what)
3014 }
3015}
3016
Jiyong Park62304bb2020-04-13 16:19:48 +09003017func (c *Module) TestFor() []string {
3018 if test, ok := c.linker.(interface {
3019 testFor() []string
3020 }); ok {
3021 return test.testFor()
3022 } else {
3023 return c.ApexModuleBase.TestFor()
3024 }
3025}
3026
Colin Crossaede88c2020-08-11 12:17:01 -07003027func (c *Module) UniqueApexVariations() bool {
3028 if u, ok := c.compiler.(interface {
3029 uniqueApexVariations() bool
3030 }); ok {
3031 return u.uniqueApexVariations()
3032 } else {
3033 return false
3034 }
3035}
3036
Paul Duffin0cb37b92020-03-04 14:52:46 +00003037// Return true if the module is ever installable.
3038func (c *Module) EverInstallable() bool {
3039 return c.installer != nil &&
3040 // Check to see whether the module is actually ever installable.
3041 c.installer.everInstallable()
3042}
3043
Colin Cross56a83212020-09-15 18:30:11 -07003044func (c *Module) installable(apexInfo android.ApexInfo) bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00003045 ret := c.EverInstallable() &&
3046 // Check to see whether the module has been configured to not be installed.
3047 proptools.BoolDefault(c.Properties.Installable, true) &&
3048 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003049
3050 // The platform variant doesn't need further condition. Apex variants however might not
3051 // be installable because it will likely to be included in the APEX and won't appear
3052 // in the system partition.
Colin Cross56a83212020-09-15 18:30:11 -07003053 if apexInfo.IsForPlatform() {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003054 return ret
3055 }
3056
3057 // Special case for modules that are configured to be installed to /data, which includes
3058 // test modules. For these modules, both APEX and non-APEX variants are considered as
3059 // installable. This is because even the APEX variants won't be included in the APEX, but
3060 // will anyway be installed to /data/*.
3061 // See b/146995717
3062 if c.InstallInData() {
3063 return ret
3064 }
3065
3066 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09003067}
3068
Logan Chien41eabe62019-04-10 13:33:58 +08003069func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
3070 if c.linker != nil {
3071 if library, ok := c.linker.(*libraryDecorator); ok {
3072 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
3073 }
3074 }
3075}
3076
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003077func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07003078 depTag := ctx.OtherModuleDependencyTag(dep)
3079 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
3080
3081 if cc, ok := dep.(*Module); ok {
3082 if cc.HasStubsVariants() {
3083 if isLibDepTag && libDepTag.shared() {
3084 // dynamic dep to a stubs lib crosses APEX boundary
3085 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003086 }
Colin Cross6e511a92020-07-27 21:26:48 -07003087 if IsRuntimeDepTag(depTag) {
3088 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003089 return false
3090 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003091 }
Colin Crossaac32222020-07-29 12:51:56 -07003092 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07003093 // shared_lib dependency from a static lib is considered as crossing
3094 // the APEX boundary because the dependency doesn't actually is
3095 // linked; the dependency is used only during the compilation phase.
3096 return false
3097 }
3098 }
3099 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09003100 // We don't track beyond LLNDK
3101 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003102 }
3103 return true
3104}
3105
Dan Albertc8060532020-07-22 22:32:17 -07003106func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3107 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003108 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3109 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3110 return nil
3111 }
3112 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3113 if c.ToolchainLibrary() {
3114 return nil
3115 }
3116 // We don't check for prebuilt modules
3117 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3118 return nil
3119 }
3120 minSdkVersion := c.MinSdkVersion()
3121 if minSdkVersion == "apex_inherit" {
3122 return nil
3123 }
3124 if minSdkVersion == "" {
3125 // JNI libs within APK-in-APEX fall into here
3126 // Those are okay to set sdk_version instead
3127 // We don't have to check if this is a SDK variant because
3128 // non-SDK variant resets sdk_version, which works too.
3129 minSdkVersion = c.SdkVersion()
3130 }
Dan Albertc8060532020-07-22 22:32:17 -07003131 if minSdkVersion == "" {
3132 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3133 }
3134 // Not using nativeApiLevelFromUser because the context here is not
3135 // necessarily a native context.
3136 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003137 if err != nil {
3138 return err
3139 }
Dan Albertc8060532020-07-22 22:32:17 -07003140
3141 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003142 return fmt.Errorf("newer SDK(%v)", ver)
3143 }
3144 return nil
3145}
3146
Colin Cross2ba19d92015-05-07 15:44:20 -07003147//
Colin Crosscfad1192015-11-02 16:43:11 -08003148// Defaults
3149//
Colin Crossca860ac2016-01-04 14:34:37 -08003150type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003151 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003152 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003153 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003154}
3155
Patrice Arrudac249c712019-03-19 17:00:29 -07003156// cc_defaults provides a set of properties that can be inherited by other cc
3157// modules. A module can use the properties from a cc_defaults using
3158// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3159// merged (when possible) by prepending the default module's values to the
3160// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003161func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003162 return DefaultsFactory()
3163}
3164
Colin Cross36242852017-06-23 15:06:31 -07003165func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003166 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003167
Colin Cross36242852017-06-23 15:06:31 -07003168 module.AddProperties(props...)
3169 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003170 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003171 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003172 &BaseCompilerProperties{},
3173 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003174 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003175 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003176 &StaticProperties{},
3177 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003178 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003179 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003180 &TestProperties{},
3181 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003182 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003183 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003184 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003185 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003186 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003187 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003188 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003189 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003190 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003191 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003192 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003193 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003194 &android.ProtoProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -04003195 // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
3196 &RustBindgenClangProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003197 )
Colin Crosscfad1192015-11-02 16:43:11 -08003198
Jooyung Hancc372c52019-09-25 15:18:44 +09003199 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003200
3201 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003202}
3203
Jiyong Park6a43f042017-10-12 23:05:00 +09003204func squashVendorSrcs(m *Module) {
3205 if lib, ok := m.compiler.(*libraryDecorator); ok {
3206 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3207 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3208
3209 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3210 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003211
3212 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3213 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003214 }
3215}
3216
Jiyong Parkf9332f12018-02-01 00:54:12 +09003217func squashRecoverySrcs(m *Module) {
3218 if lib, ok := m.compiler.(*libraryDecorator); ok {
3219 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3220 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3221
3222 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3223 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003224
3225 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3226 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003227 }
3228}
3229
Jiyong Park2286afd2020-06-16 21:58:53 +09003230func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003231 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003232}
3233
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003234func kytheExtractAllFactory() android.Singleton {
3235 return &kytheExtractAllSingleton{}
3236}
3237
3238type kytheExtractAllSingleton struct {
3239}
3240
3241func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3242 var xrefTargets android.Paths
3243 ctx.VisitAllModules(func(module android.Module) {
3244 if ccModule, ok := module.(xref); ok {
3245 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3246 }
3247 })
3248 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3249 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003250 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003251 }
3252}
3253
Colin Cross06a931b2015-10-28 17:23:31 -07003254var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003255var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003256var BoolPtr = proptools.BoolPtr
3257var String = proptools.String
3258var StringPtr = proptools.StringPtr