blob: 7c34b518283394516ac12bebf71141e667098b99 [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
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800103 StaticUnwinderIfLegacy bool
104
Colin Cross5950f382016-12-13 12:50:57 -0800105 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700106
Colin Cross81413472016-04-11 14:37:39 -0700107 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700108
Dan Willemsenb40aab62016-04-20 14:21:14 -0700109 GeneratedSources []string
110 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900111 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700112
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700113 ReexportGeneratedHeaders []string
114
Colin Cross97ba0732015-03-23 17:50:24 -0700115 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700116
117 // Used for host bionic
118 LinkerFlagsFile string
119 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700120}
121
Colin Crossca860ac2016-01-04 14:34:37 -0800122type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700123 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900124 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700125 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900126 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700127 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700128 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700129
Colin Cross26c34ed2016-09-30 17:10:16 -0700130 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100131 Objs Objects
132 // Paths to .o files in dependencies that provide them. Note that these lists
133 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800134 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700135 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700136
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100137 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
138 // the libs from all whole_static_lib dependencies.
139 WholeStaticLibsFromPrebuilts android.Paths
140
Colin Cross26c34ed2016-09-30 17:10:16 -0700141 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700142 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900143 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700144
Inseob Kimd110f872019-12-06 13:15:38 +0900145 Flags []string
146 IncludeDirs android.Paths
147 SystemIncludeDirs android.Paths
148 ReexportedDirs android.Paths
149 ReexportedSystemDirs android.Paths
150 ReexportedFlags []string
151 ReexportedGeneratedHeaders android.Paths
152 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700153
Colin Cross26c34ed2016-09-30 17:10:16 -0700154 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700155 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700156
157 // Path to the file container flags to use with the linker
158 LinkerFlagsFile android.OptionalPath
159
160 // Path to the dynamic linker binary
161 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700162}
163
Colin Cross4af21ed2019-11-04 09:37:55 -0800164// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
165// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
166// command line so they can be overridden by the local module flags).
167type LocalOrGlobalFlags struct {
168 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700169 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800170 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700171 CFlags []string // Flags that apply to C and C++ source files
172 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
173 ConlyFlags []string // Flags that apply to C source files
174 CppFlags []string // Flags that apply to C++ source files
175 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700176 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800177}
178
179type Flags struct {
180 Local LocalOrGlobalFlags
181 Global LocalOrGlobalFlags
182
183 aidlFlags []string // Flags that apply to aidl source files
184 rsFlags []string // Flags that apply to renderscript source files
185 libFlags []string // Flags to add libraries early to the link order
186 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
187 TidyFlags []string // Flags that apply to clang-tidy
188 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700189
Colin Crossc3199482017-03-30 15:03:04 -0700190 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800191 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700192 SystemIncludeFlags []string
193
Oliver Nguyen04526782020-04-21 12:40:27 -0700194 Toolchain config.Toolchain
195 Tidy bool
196 GcovCoverage bool
197 SAbiDump bool
198 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800199
200 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800201 DynamicLinker string
202
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700203 CFlagsDeps android.Paths // Files depended on by compiler flags
204 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800205
Dan Willemsen98ab3112019-08-27 21:20:40 -0700206 AssemblerWithCpp bool
207 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800208
Colin Cross19878da2019-03-28 14:45:07 -0700209 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700210 protoC bool // Whether to use C instead of C++
211 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700212
213 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200214 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700215}
216
Colin Crossca860ac2016-01-04 14:34:37 -0800217// Properties used to compile all C or C++ modules
218type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700219 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800220 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700221
Colin Crossc511bc52020-04-07 16:50:32 +0000222 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
223 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800224 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700225
Jooyung Han379660c2020-04-21 15:24:00 +0900226 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
227 Min_sdk_version *string
228
Colin Crossc511bc52020-04-07 16:50:32 +0000229 // If true, always create an sdk variant and don't create a platform variant.
230 Sdk_variant_only *bool
231
Jiyong Parkde866cb2018-12-07 23:08:36 +0900232 AndroidMkSharedLibs []string `blueprint:"mutated"`
233 AndroidMkStaticLibs []string `blueprint:"mutated"`
234 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
235 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700236 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900237 HideFromMake bool `blueprint:"mutated"`
238 PreventInstall bool `blueprint:"mutated"`
239 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700240
Justin Yun5f7f7e82019-11-18 19:52:14 +0900241 ImageVariationPrefix string `blueprint:"mutated"`
242 VndkVersion string `blueprint:"mutated"`
243 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800244
245 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
246 // file
247 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900248
Yifan Hong1b3348d2020-01-21 15:53:22 -0800249 // Make this module available when building for ramdisk
250 Ramdisk_available *bool
251
Jiyong Parkf9332f12018-02-01 00:54:12 +0900252 // Make this module available when building for recovery
253 Recovery_available *bool
254
Colin Crossae6c5202019-11-20 13:35:50 -0800255 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800256 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800257 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800258 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900259 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900260
261 // Allows this module to use non-APEX version of libraries. Useful
262 // for building binaries that are started before APEXes are activated.
263 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900264
265 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
266 // see soong/cc/config/vndk.go
267 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900268
269 // Used by vendor snapshot to record dependencies from snapshot modules.
270 SnapshotSharedLibs []string `blueprint:"mutated"`
271 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000272
273 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000274
275 // Set by factories of module types that can only be referenced from variants compiled against
276 // the SDK.
277 AlwaysSdk bool `blueprint:"mutated"`
278
279 // Variant is an SDK variant created by sdkMutator
280 IsSdkVariant bool `blueprint:"mutated"`
281 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
282 // variant to have a ".sdk" suffix.
283 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700284
285 // Normally Soong uses the directory structure to decide which modules
286 // should be included (framework) or excluded (non-framework) from the
287 // vendor snapshot, but this property allows a partner to exclude a
288 // module normally thought of as a framework module from the vendor
289 // snapshot.
290 Exclude_from_vendor_snapshot *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700291}
292
293type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900294 // whether this module should be allowed to be directly depended by other
295 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900296 // In addition, this module should be allowed to be directly depended by
297 // product modules with `product_specific: true`.
298 // If set to true, three variants will be built separately, one like
299 // normal, another limited to the set of libraries and headers
300 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700301 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900302 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700303 // so it shouldn't have any unversioned runtime dependencies, or
304 // make assumptions about the system that may not be true in the
305 // future.
306 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900307 // If set to false, this module becomes inaccessible from /vendor or /product
308 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900309 //
310 // Default value is true when vndk: {enabled: true} or vendor: true.
311 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700312 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900313 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700314 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900315
316 // whether this module is capable of being loaded with other instance
317 // (possibly an older version) of the same module in the same process.
318 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
319 // can be double loaded in a vendor process if the library is also a
320 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
321 // explicitly marked as `double_loadable: true` by the owner, or the dependency
322 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
323 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800324}
325
Colin Crossca860ac2016-01-04 14:34:37 -0800326type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800327 static() bool
328 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900329 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900330 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900331 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700332 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900333 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700334 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800335 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700336 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800337 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900338 isLlndk(config android.Config) bool
339 isLlndkPublic(config android.Config) bool
340 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900341 isVndk() bool
342 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800343 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900344 inProduct() bool
345 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800346 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900347 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800348 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700349 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700350 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800351 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800352 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800353 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800354 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800355 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700356 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700357 apexSdkVersion() android.ApiLevel
Jiyong Parkb0788572018-12-20 22:10:17 +0900358 hasStubsVariants() bool
359 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900360 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800361 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700362 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800363}
364
365type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700366 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800367 ModuleContextIntf
368}
369
370type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700371 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800372 ModuleContextIntf
373}
374
Colin Cross37047f12016-12-13 17:06:13 -0800375type DepsContext interface {
376 android.BottomUpMutatorContext
377 ModuleContextIntf
378}
379
Colin Crossca860ac2016-01-04 14:34:37 -0800380type feature interface {
381 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800382 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800383 flags(ctx ModuleContext, flags Flags) Flags
384 props() []interface{}
385}
386
387type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700388 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800389 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800390 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700391 compilerProps() []interface{}
392
Colin Cross76fada02016-07-27 10:31:13 -0700393 appendCflags([]string)
394 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700395 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800396}
397
398type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700399 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800400 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700401 linkerFlags(ctx ModuleContext, flags Flags) Flags
402 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800403 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700404
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700405 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700406 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900407 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700408
409 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900410 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000411
412 // Get the deps that have been explicitly specified in the properties.
413 // Only updates the
414 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
415}
416
417type specifiedDeps struct {
418 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000419 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800420}
421
422type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700423 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700424 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000425 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800426 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700427 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700428 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900429 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100430 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800431}
432
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800433type xref interface {
434 XrefCcFiles() android.Paths
435}
436
Colin Cross6e511a92020-07-27 21:26:48 -0700437type libraryDependencyKind int
438
439const (
440 headerLibraryDependency = iota
441 sharedLibraryDependency
442 staticLibraryDependency
443)
444
445func (k libraryDependencyKind) String() string {
446 switch k {
447 case headerLibraryDependency:
448 return "headerLibraryDependency"
449 case sharedLibraryDependency:
450 return "sharedLibraryDependency"
451 case staticLibraryDependency:
452 return "staticLibraryDependency"
453 default:
454 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
455 }
456}
457
458type libraryDependencyOrder int
459
460const (
461 earlyLibraryDependency = -1
462 normalLibraryDependency = 0
463 lateLibraryDependency = 1
464)
465
466func (o libraryDependencyOrder) String() string {
467 switch o {
468 case earlyLibraryDependency:
469 return "earlyLibraryDependency"
470 case normalLibraryDependency:
471 return "normalLibraryDependency"
472 case lateLibraryDependency:
473 return "lateLibraryDependency"
474 default:
475 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
476 }
477}
478
479// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
480// tags that have a set of predefined tag objects that are reused for each dependency, a
481// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
482// That means that comparing a libraryDependencyTag for equality will only be equal if all
483// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
484// then check individual metadata fields instead.
485type libraryDependencyTag struct {
486 blueprint.BaseDependencyTag
487
488 // These are exported so that fmt.Printf("%#v") can call their String methods.
489 Kind libraryDependencyKind
490 Order libraryDependencyOrder
491
492 wholeStatic bool
493
494 reexportFlags bool
495 explicitlyVersioned bool
496 dataLib bool
497 ndk bool
498
499 staticUnwinder bool
500
501 makeSuffix string
502}
503
504// header returns true if the libraryDependencyTag is tagging a header lib dependency.
505func (d libraryDependencyTag) header() bool {
506 return d.Kind == headerLibraryDependency
507}
508
509// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
510func (d libraryDependencyTag) shared() bool {
511 return d.Kind == sharedLibraryDependency
512}
513
514// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
515func (d libraryDependencyTag) static() bool {
516 return d.Kind == staticLibraryDependency
517}
518
519// dependencyTag is used for tagging miscellanous dependency types that don't fit into
520// libraryDependencyTag. Each tag object is created globally and reused for multiple
521// dependencies (although since the object contains no references, assigning a tag to a
522// variable and modifying it will not modify the original). Users can compare the tag
523// returned by ctx.OtherModuleDependencyTag against the global original
524type dependencyTag struct {
525 blueprint.BaseDependencyTag
526 name string
527}
528
Colin Crossc99deeb2016-04-11 15:06:20 -0700529var (
Colin Cross6e511a92020-07-27 21:26:48 -0700530 genSourceDepTag = dependencyTag{name: "gen source"}
531 genHeaderDepTag = dependencyTag{name: "gen header"}
532 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
533 objDepTag = dependencyTag{name: "obj"}
534 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
535 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
536 reuseObjTag = dependencyTag{name: "reuse objects"}
537 staticVariantTag = dependencyTag{name: "static variant"}
538 vndkExtDepTag = dependencyTag{name: "vndk extends"}
539 dataLibDepTag = dependencyTag{name: "data lib"}
540 runtimeDepTag = dependencyTag{name: "runtime lib"}
541 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700542)
543
Roland Levillainf89cd092019-07-29 16:22:59 +0100544func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700545 ccLibDepTag, ok := depTag.(libraryDependencyTag)
546 return ok && ccLibDepTag.shared()
547}
548
549func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
550 ccLibDepTag, ok := depTag.(libraryDependencyTag)
551 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100552}
553
554func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700555 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100556 return ok && ccDepTag == runtimeDepTag
557}
558
559func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700560 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100561 return ok && ccDepTag == testPerSrcDepTag
562}
563
Colin Crossca860ac2016-01-04 14:34:37 -0800564// Module contains the properties and members used by all C/C++ module types, and implements
565// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
566// to construct the output file. Behavior can be customized with a Customizer interface
567type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700568 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700569 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900570 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900571 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700572
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700573 Properties BaseProperties
574 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700575
Colin Crossca860ac2016-01-04 14:34:37 -0800576 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700577 hod android.HostOrDeviceSupported
578 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700579
Paul Duffina0843f62019-12-13 19:50:38 +0000580 // Allowable SdkMemberTypes of this module type.
581 sdkMemberTypes []android.SdkMemberType
582
Colin Crossca860ac2016-01-04 14:34:37 -0800583 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700584 features []feature
585 compiler compiler
586 linker linker
587 installer installer
588 stl *stl
589 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800590 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800591 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900592 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700593 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700594 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800595
Colin Cross635c3b02016-05-18 15:37:25 -0700596 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800597
Colin Crossb98c8b02016-07-29 13:44:28 -0700598 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700599
600 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800601
602 // Flags used to compile this module
603 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700604
605 // 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 -0800606 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700607 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800608 depsInLinkOrder android.Paths
609
610 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700611 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900612
613 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800614 // Kythe (source file indexer) paths for this compilation module
615 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900616
617 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700618 apexSdkVersion android.ApiLevel
Colin Crossc472d572015-03-17 15:06:21 -0700619}
620
Ivan Lozano52767be2019-10-18 14:49:46 -0700621func (c *Module) Toc() android.OptionalPath {
622 if c.linker != nil {
623 if library, ok := c.linker.(libraryInterface); ok {
624 return library.toc()
625 }
626 }
627 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
628}
629
630func (c *Module) ApiLevel() string {
631 if c.linker != nil {
632 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -0700633 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -0700634 }
635 }
636 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
637}
638
639func (c *Module) Static() bool {
640 if c.linker != nil {
641 if library, ok := c.linker.(libraryInterface); ok {
642 return library.static()
643 }
644 }
645 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
646}
647
648func (c *Module) Shared() bool {
649 if c.linker != nil {
650 if library, ok := c.linker.(libraryInterface); ok {
651 return library.shared()
652 }
653 }
654 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
655}
656
657func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000658 if c.stl != nil {
659 return c.stl.Properties.SelectedStl
660 }
661 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700662}
663
664func (c *Module) ToolchainLibrary() bool {
665 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
666 return true
667 }
668 return false
669}
670
671func (c *Module) NdkPrebuiltStl() bool {
672 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
673 return true
674 }
675 return false
676}
677
678func (c *Module) StubDecorator() bool {
679 if _, ok := c.linker.(*stubDecorator); ok {
680 return true
681 }
682 return false
683}
684
685func (c *Module) SdkVersion() string {
686 return String(c.Properties.Sdk_version)
687}
688
Artur Satayev480e25b2020-04-27 18:53:18 +0100689func (c *Module) MinSdkVersion() string {
690 return String(c.Properties.Min_sdk_version)
691}
692
Dan Albert92fe7402020-07-15 13:33:30 -0700693func (c *Module) SplitPerApiLevel() bool {
694 if linker, ok := c.linker.(*objectLinker); ok {
695 return linker.isCrt()
696 }
697 return false
698}
699
Colin Crossc511bc52020-04-07 16:50:32 +0000700func (c *Module) AlwaysSdk() bool {
701 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
702}
703
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800704func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700705 if c.linker != nil {
706 if library, ok := c.linker.(exportedFlagsProducer); ok {
707 return library.exportedDirs()
708 }
709 }
710 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
711}
712
713func (c *Module) HasStaticVariant() bool {
714 if c.staticVariant != nil {
715 return true
716 }
717 return false
718}
719
720func (c *Module) GetStaticVariant() LinkableInterface {
721 return c.staticVariant
722}
723
724func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
725 c.depsInLinkOrder = depsInLinkOrder
726}
727
728func (c *Module) GetDepsInLinkOrder() []android.Path {
729 return c.depsInLinkOrder
730}
731
732func (c *Module) StubsVersions() []string {
733 if c.linker != nil {
734 if library, ok := c.linker.(*libraryDecorator); ok {
735 return library.Properties.Stubs.Versions
736 }
737 }
738 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
739}
740
741func (c *Module) CcLibrary() bool {
742 if c.linker != nil {
743 if _, ok := c.linker.(*libraryDecorator); ok {
744 return true
745 }
746 }
747 return false
748}
749
750func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700751 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700752 return true
753 }
754 return false
755}
756
Ivan Lozano2b262972019-11-21 12:30:50 -0800757func (c *Module) NonCcVariants() bool {
758 return false
759}
760
Ivan Lozano183a3212019-10-18 14:18:45 -0700761func (c *Module) SetBuildStubs() {
762 if c.linker != nil {
763 if library, ok := c.linker.(*libraryDecorator); ok {
764 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700765 c.Properties.HideFromMake = true
766 c.sanitize = nil
767 c.stl = nil
768 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700769 return
770 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000771 if _, ok := c.linker.(*llndkStubDecorator); ok {
772 c.Properties.HideFromMake = true
773 return
774 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700775 }
776 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
777}
778
Ivan Lozano52767be2019-10-18 14:49:46 -0700779func (c *Module) BuildStubs() bool {
780 if c.linker != nil {
781 if library, ok := c.linker.(*libraryDecorator); ok {
782 return library.buildStubs()
783 }
784 }
785 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
786}
787
Colin Crossd1f898e2020-08-18 18:35:15 -0700788func (c *Module) SetAllStubsVersions(versions []string) {
789 if library, ok := c.linker.(*libraryDecorator); ok {
790 library.MutatedProperties.AllStubsVersions = versions
791 return
792 }
793 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
794 llndk.libraryDecorator.MutatedProperties.AllStubsVersions = versions
795 return
796 }
797}
798
799func (c *Module) AllStubsVersions() []string {
800 if library, ok := c.linker.(*libraryDecorator); ok {
801 return library.MutatedProperties.AllStubsVersions
802 }
803 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
804 return llndk.libraryDecorator.MutatedProperties.AllStubsVersions
805 }
806 return nil
807}
808
809func (c *Module) SetStubsVersion(version string) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700810 if c.linker != nil {
811 if library, ok := c.linker.(*libraryDecorator); ok {
812 library.MutatedProperties.StubsVersion = version
813 return
814 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000815 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
816 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
817 return
818 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700819 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700820 panic(fmt.Errorf("SetStubsVersion called on non-library module: %q", c.BaseModuleName()))
Ivan Lozano183a3212019-10-18 14:18:45 -0700821}
822
Jooyung Han03b51852020-02-26 22:45:42 +0900823func (c *Module) StubsVersion() string {
824 if c.linker != nil {
825 if library, ok := c.linker.(*libraryDecorator); ok {
826 return library.MutatedProperties.StubsVersion
827 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000828 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
829 return llndk.libraryDecorator.MutatedProperties.StubsVersion
830 }
Jooyung Han03b51852020-02-26 22:45:42 +0900831 }
832 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
833}
834
Ivan Lozano183a3212019-10-18 14:18:45 -0700835func (c *Module) SetStatic() {
836 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700837 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700838 library.setStatic()
839 return
840 }
841 }
842 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
843}
844
845func (c *Module) SetShared() {
846 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700847 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700848 library.setShared()
849 return
850 }
851 }
852 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
853}
854
855func (c *Module) BuildStaticVariant() bool {
856 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700857 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700858 return library.buildStatic()
859 }
860 }
861 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
862}
863
864func (c *Module) BuildSharedVariant() bool {
865 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700866 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700867 return library.buildShared()
868 }
869 }
870 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
871}
872
873func (c *Module) Module() android.Module {
874 return c
875}
876
Jiyong Parkc20eee32018-09-05 22:36:17 +0900877func (c *Module) OutputFile() android.OptionalPath {
878 return c.outputFile
879}
880
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400881func (c *Module) CoverageFiles() android.Paths {
882 if c.linker != nil {
883 if library, ok := c.linker.(libraryInterface); ok {
884 return library.objs().coverageFiles
885 }
886 }
887 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
888}
889
Ivan Lozano183a3212019-10-18 14:18:45 -0700890var _ LinkableInterface = (*Module)(nil)
891
Jiyong Park719b4462019-01-13 00:39:51 +0900892func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900893 if c.linker != nil {
894 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900895 }
896 return nil
897}
898
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900899func (c *Module) CoverageOutputFile() android.OptionalPath {
900 if c.linker != nil {
901 return c.linker.coverageOutputFilePath()
902 }
903 return android.OptionalPath{}
904}
905
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900906func (c *Module) RelativeInstallPath() string {
907 if c.installer != nil {
908 return c.installer.relativeInstallPath()
909 }
910 return ""
911}
912
Jooyung Han344d5432019-08-23 11:17:39 +0900913func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900914 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900915}
916
Colin Cross36242852017-06-23 15:06:31 -0700917func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700918 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800919 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700920 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800921 }
922 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700923 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800924 }
925 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700926 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800927 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700928 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700929 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700930 }
Colin Cross16b23492016-01-06 14:41:07 -0800931 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700932 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800933 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800934 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700935 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800936 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800937 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700938 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800939 }
Justin Yun8effde42017-06-23 19:24:43 +0900940 if c.vndkdep != nil {
941 c.AddProperties(c.vndkdep.props()...)
942 }
Stephen Craneba090d12017-05-09 15:44:35 -0700943 if c.lto != nil {
944 c.AddProperties(c.lto.props()...)
945 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700946 if c.pgo != nil {
947 c.AddProperties(c.pgo.props()...)
948 }
Colin Crossca860ac2016-01-04 14:34:37 -0800949 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700950 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800951 }
Colin Crossc472d572015-03-17 15:06:21 -0700952
Jiyong Park1613e552020-09-14 19:43:17 +0900953 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700954 // Windows builds always prefer 32-bit
Jiyong Park1613e552020-09-14 19:43:17 +0900955 return os == android.Windows
Colin Crossa9d8bee2018-10-02 13:59:46 -0700956 })
Colin Cross36242852017-06-23 15:06:31 -0700957 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900958 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900959 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900960 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900961
Colin Cross36242852017-06-23 15:06:31 -0700962 return c
Colin Crossc472d572015-03-17 15:06:21 -0700963}
964
Colin Crossb916a382016-07-29 17:28:03 -0700965// Returns true for dependency roots (binaries)
966// TODO(ccross): also handle dlopenable libraries
967func (c *Module) isDependencyRoot() bool {
968 if root, ok := c.linker.(interface {
969 isDependencyRoot() bool
970 }); ok {
971 return root.isDependencyRoot()
972 }
973 return false
974}
975
Justin Yun5f7f7e82019-11-18 19:52:14 +0900976// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
977// "product" and "vendor" variant modules return true for this function.
978// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
979// "soc_specific: true" and more vendor installed modules are included here.
980// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
981// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700982func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900983 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700984}
985
Colin Crossc511bc52020-04-07 16:50:32 +0000986func (c *Module) canUseSdk() bool {
987 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
988}
989
990func (c *Module) UseSdk() bool {
991 if c.canUseSdk() {
Dan Albert92fe7402020-07-15 13:33:30 -0700992 return String(c.Properties.Sdk_version) != "" || c.SplitPerApiLevel()
Colin Crossc511bc52020-04-07 16:50:32 +0000993 }
994 return false
995}
996
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800997func (c *Module) isCoverageVariant() bool {
998 return c.coverage.Properties.IsCoverageVariant
999}
1000
Peter Collingbournead84f972019-12-17 16:46:18 -08001001func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -07001002 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001003}
1004
Inseob Kim9516ee92019-05-09 10:56:13 +09001005func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001006 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001007 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001008}
1009
Inseob Kim9516ee92019-05-09 10:56:13 +09001010func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001011 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001012 name := c.BaseModuleName()
1013 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001014}
1015
Inseob Kim9516ee92019-05-09 10:56:13 +09001016func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001017 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +09001018 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001019}
1020
Ivan Lozano52767be2019-10-18 14:49:46 -07001021func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001022 if vndkdep := c.vndkdep; vndkdep != nil {
1023 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001024 }
1025 return false
1026}
1027
Yi Kong7e53c572018-02-14 18:16:12 +08001028func (c *Module) isPgoCompile() bool {
1029 if pgo := c.pgo; pgo != nil {
1030 return pgo.Properties.PgoCompile
1031 }
1032 return false
1033}
1034
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001035func (c *Module) isNDKStubLibrary() bool {
1036 if _, ok := c.compiler.(*stubDecorator); ok {
1037 return true
1038 }
1039 return false
1040}
1041
Logan Chienf3511742017-10-31 18:04:35 +08001042func (c *Module) isVndkSp() bool {
1043 if vndkdep := c.vndkdep; vndkdep != nil {
1044 return vndkdep.isVndkSp()
1045 }
1046 return false
1047}
1048
1049func (c *Module) isVndkExt() bool {
1050 if vndkdep := c.vndkdep; vndkdep != nil {
1051 return vndkdep.isVndkExt()
1052 }
1053 return false
1054}
1055
Ivan Lozano52767be2019-10-18 14:49:46 -07001056func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001057 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001058}
1059
Logan Chienf3511742017-10-31 18:04:35 +08001060func (c *Module) getVndkExtendsModuleName() string {
1061 if vndkdep := c.vndkdep; vndkdep != nil {
1062 return vndkdep.getVndkExtendsModuleName()
1063 }
1064 return ""
1065}
1066
Jiyong Park25fc6a92018-11-18 18:02:45 +09001067func (c *Module) IsStubs() bool {
1068 if library, ok := c.linker.(*libraryDecorator); ok {
1069 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001070 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1071 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001072 }
1073 return false
1074}
1075
1076func (c *Module) HasStubsVariants() bool {
1077 if library, ok := c.linker.(*libraryDecorator); ok {
1078 return len(library.Properties.Stubs.Versions) > 0
1079 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001080 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1081 return len(library.Properties.Stubs.Versions) > 0
1082 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001083 return false
1084}
1085
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001086func (c *Module) bootstrap() bool {
1087 return Bool(c.Properties.Bootstrap)
1088}
1089
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001090func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001091 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1092 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1093 return false
1094 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001095 return c.linker != nil && c.linker.nativeCoverage()
1096}
1097
Inseob Kim8471cda2019-11-15 09:59:12 +09001098func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001099 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1100 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001101 }
1102 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001103}
1104
Jiyong Park73c54ee2019-10-22 20:31:18 +09001105func (c *Module) ExportedIncludeDirs() android.Paths {
1106 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1107 return flagsProducer.exportedDirs()
1108 }
Jiyong Park232e7852019-11-04 12:23:40 +09001109 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001110}
1111
1112func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1113 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1114 return flagsProducer.exportedSystemDirs()
1115 }
Jiyong Park232e7852019-11-04 12:23:40 +09001116 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001117}
1118
1119func (c *Module) ExportedFlags() []string {
1120 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1121 return flagsProducer.exportedFlags()
1122 }
Jiyong Park232e7852019-11-04 12:23:40 +09001123 return nil
1124}
1125
1126func (c *Module) ExportedDeps() android.Paths {
1127 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1128 return flagsProducer.exportedDeps()
1129 }
1130 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001131}
1132
Inseob Kimd110f872019-12-06 13:15:38 +09001133func (c *Module) ExportedGeneratedHeaders() android.Paths {
1134 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1135 return flagsProducer.exportedGeneratedHeaders()
1136 }
1137 return nil
1138}
1139
Bill Peckham945441c2020-08-31 16:07:58 -07001140func (c *Module) ExcludeFromVendorSnapshot() bool {
1141 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1142}
1143
Jiyong Parkf1194352019-02-25 11:05:47 +09001144func isBionic(name string) bool {
1145 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001146 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001147 return true
1148 }
1149 return false
1150}
1151
Martin Stjernholm279de572019-09-10 23:18:20 +01001152func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001153 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001154 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001155 }
1156 return isBionic(name)
1157}
1158
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001159func (c *Module) XrefCcFiles() android.Paths {
1160 return c.kytheFiles
1161}
1162
Colin Crossca860ac2016-01-04 14:34:37 -08001163type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001164 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001165 moduleContextImpl
1166}
1167
Colin Cross37047f12016-12-13 17:06:13 -08001168type depsContext struct {
1169 android.BottomUpMutatorContext
1170 moduleContextImpl
1171}
1172
Colin Crossca860ac2016-01-04 14:34:37 -08001173type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001174 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001175 moduleContextImpl
1176}
1177
1178type moduleContextImpl struct {
1179 mod *Module
1180 ctx BaseModuleContext
1181}
1182
Colin Crossb98c8b02016-07-29 13:44:28 -07001183func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001184 return ctx.mod.toolchain(ctx.ctx)
1185}
1186
1187func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001188 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001189}
1190
1191func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001192 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001193}
1194
Jiyong Park1d1119f2019-07-29 21:27:18 +09001195func (ctx *moduleContextImpl) header() bool {
1196 return ctx.mod.header()
1197}
1198
Inseob Kim7f283f42020-06-01 21:53:49 +09001199func (ctx *moduleContextImpl) binary() bool {
1200 return ctx.mod.binary()
1201}
1202
Inseob Kim1042d292020-06-01 23:23:05 +09001203func (ctx *moduleContextImpl) object() bool {
1204 return ctx.mod.object()
1205}
1206
Jooyung Hanccce2f22020-03-07 03:45:53 +09001207func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001208 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001209}
1210
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001211func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001212 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001213}
1214
1215func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001216 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001217 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001218 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001219 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001220 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001221 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001222 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001223 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001224 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001225 }
1226 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001227}
1228
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001229func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001230 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001231}
Justin Yun8effde42017-06-23 19:24:43 +09001232
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001233func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001234 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001235}
1236
Inseob Kim9516ee92019-05-09 10:56:13 +09001237func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1238 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001239}
1240
Inseob Kim9516ee92019-05-09 10:56:13 +09001241func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1242 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001243}
1244
Inseob Kim9516ee92019-05-09 10:56:13 +09001245func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1246 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001247}
1248
Logan Chienf3511742017-10-31 18:04:35 +08001249func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001250 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001251}
1252
Yi Kong7e53c572018-02-14 18:16:12 +08001253func (ctx *moduleContextImpl) isPgoCompile() bool {
1254 return ctx.mod.isPgoCompile()
1255}
1256
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001257func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1258 return ctx.mod.isNDKStubLibrary()
1259}
1260
Justin Yun8effde42017-06-23 19:24:43 +09001261func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001262 return ctx.mod.isVndkSp()
1263}
1264
1265func (ctx *moduleContextImpl) isVndkExt() bool {
1266 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001267}
1268
Vic Yangefd249e2018-11-12 20:19:56 -08001269func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001270 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001271}
1272
Logan Chien2f2b8902018-07-10 15:01:19 +08001273// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001274func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001275 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1276 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001277 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001278
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001279 // Coverage builds have extra symbols.
1280 if ctx.mod.isCoverageVariant() {
1281 return false
1282 }
1283
Doug Hornc32c6b02019-01-17 14:44:05 -08001284 if ctx.ctx.Fuchsia() {
1285 return false
1286 }
1287
Logan Chien2f2b8902018-07-10 15:01:19 +08001288 if sanitize := ctx.mod.sanitize; sanitize != nil {
1289 if !sanitize.isVariantOnProductionDevice() {
1290 return false
1291 }
1292 }
1293 if !ctx.ctx.Device() {
1294 // Host modules do not need ABI dumps.
1295 return false
1296 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001297 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001298 // Stubs do not need ABI dumps.
1299 return false
1300 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001301 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001302}
1303
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001304func (ctx *moduleContextImpl) selectedStl() string {
1305 if stl := ctx.mod.stl; stl != nil {
1306 return stl.Properties.SelectedStl
1307 }
1308 return ""
1309}
1310
Ivan Lozanobd721262018-11-27 14:33:03 -08001311func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1312 return ctx.mod.linker.useClangLld(actx)
1313}
1314
Colin Crossce75d2c2016-10-06 16:12:58 -07001315func (ctx *moduleContextImpl) baseModuleName() string {
1316 return ctx.mod.ModuleBase.BaseModuleName()
1317}
1318
Logan Chienf3511742017-10-31 18:04:35 +08001319func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1320 return ctx.mod.getVndkExtendsModuleName()
1321}
1322
Logan Chiene274fc92019-12-03 11:18:32 -08001323func (ctx *moduleContextImpl) isForPlatform() bool {
1324 return ctx.mod.IsForPlatform()
1325}
1326
Colin Crosse07f2312020-08-13 11:24:56 -07001327func (ctx *moduleContextImpl) apexVariationName() string {
1328 return ctx.mod.ApexVariationName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001329}
1330
Dan Albertc8060532020-07-22 22:32:17 -07001331func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001332 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001333}
1334
Jiyong Parkb0788572018-12-20 22:10:17 +09001335func (ctx *moduleContextImpl) hasStubsVariants() bool {
1336 return ctx.mod.HasStubsVariants()
1337}
1338
1339func (ctx *moduleContextImpl) isStubs() bool {
1340 return ctx.mod.IsStubs()
1341}
1342
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001343func (ctx *moduleContextImpl) bootstrap() bool {
1344 return ctx.mod.bootstrap()
1345}
1346
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001347func (ctx *moduleContextImpl) nativeCoverage() bool {
1348 return ctx.mod.nativeCoverage()
1349}
1350
Colin Cross635c3b02016-05-18 15:37:25 -07001351func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001352 return &Module{
1353 hod: hod,
1354 multilib: multilib,
1355 }
1356}
1357
Colin Cross635c3b02016-05-18 15:37:25 -07001358func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001359 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001360 module.features = []feature{
1361 &tidyFeature{},
1362 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001363 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001364 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001365 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001366 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001367 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001368 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001369 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001370 return module
1371}
1372
Colin Crossce75d2c2016-10-06 16:12:58 -07001373func (c *Module) Prebuilt() *android.Prebuilt {
1374 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1375 return p.prebuilt()
1376 }
1377 return nil
1378}
1379
1380func (c *Module) Name() string {
1381 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001382 if p, ok := c.linker.(interface {
1383 Name(string) string
1384 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001385 name = p.Name(name)
1386 }
1387 return name
1388}
1389
Alex Light3d673592019-01-18 14:37:31 -08001390func (c *Module) Symlinks() []string {
1391 if p, ok := c.installer.(interface {
1392 symlinkList() []string
1393 }); ok {
1394 return p.symlinkList()
1395 }
1396 return nil
1397}
1398
Jeff Gaston294356f2017-09-27 17:05:30 -07001399// orderDeps reorders dependencies into a list such that if module A depends on B, then
1400// A will precede B in the resultant list.
1401// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001402// Note that directSharedDeps should be the analogous static library for each shared lib dep
1403func 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 -07001404 // If A depends on B, then
1405 // Every list containing A will also contain B later in the list
1406 // So, after concatenating all lists, the final instance of B will have come from the same
1407 // original list as the final instance of A
1408 // So, the final instance of B will be later in the concatenation than the final A
1409 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1410 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001411 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001412 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001413 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1414 }
1415 for _, dep := range directSharedDeps {
1416 orderedAllDeps = append(orderedAllDeps, dep)
1417 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001418 }
1419
Colin Crossb6715442017-10-24 11:13:31 -07001420 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001421
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001422 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001423 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001424 // resultant list to only what the caller has chosen to include in directStaticDeps
1425 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001426
1427 return orderedAllDeps, orderedDeclaredDeps
1428}
1429
Ivan Lozano183a3212019-10-18 14:18:45 -07001430func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001431 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001432 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001433 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1434 staticDepFiles := []android.Path{}
1435 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001436 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1437 if dep.OutputFile().Valid() {
1438 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1439 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1440 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001441 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001442 sharedDepFiles := []android.Path{}
1443 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001444 if sharedDep.HasStaticVariant() {
1445 staticAnalogue := sharedDep.GetStaticVariant()
1446 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1447 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001448 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001449 }
1450
1451 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001452 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1453 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001454
1455 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001456}
1457
Roland Levillainf89cd092019-07-29 16:22:59 +01001458func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1459 test, ok := c.linker.(testPerSrc)
1460 return ok && test.isAllTestsVariation()
1461}
1462
Chris Parsons216e10a2020-07-09 17:12:52 -04001463func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001464 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001465 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001466 }); ok {
1467 return p.dataPaths()
1468 }
1469 return nil
1470}
1471
Justin Yun5f7f7e82019-11-18 19:52:14 +09001472func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1473 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1474 // "current", it will append the VNDK version to the name suffix.
1475 var vndkVersion string
1476 var nameSuffix string
1477 if c.inProduct() {
1478 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1479 nameSuffix = productSuffix
1480 } else {
1481 vndkVersion = ctx.DeviceConfig().VndkVersion()
1482 nameSuffix = vendorSuffix
1483 }
1484 if vndkVersion == "current" {
1485 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1486 }
1487 if c.Properties.VndkVersion != vndkVersion {
1488 // add version suffix only if the module is using different vndk version than the
1489 // version in product or vendor partition.
1490 nameSuffix += "." + c.Properties.VndkVersion
1491 }
1492 return nameSuffix
1493}
1494
Colin Cross635c3b02016-05-18 15:37:25 -07001495func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001496 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001497 //
1498 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1499 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1500 // module and return early, as this module does not produce an output file per se.
1501 if c.IsTestPerSrcAllTestsVariation() {
1502 c.outputFile = android.OptionalPath{}
1503 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001504 }
1505
Jooyung Han38002912019-05-16 04:01:54 +09001506 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001507
Inseob Kim64c43952019-08-26 16:52:35 +09001508 c.Properties.SubName = ""
1509
1510 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1511 c.Properties.SubName += nativeBridgeSuffix
1512 }
1513
Justin Yun5f7f7e82019-11-18 19:52:14 +09001514 _, llndk := c.linker.(*llndkStubDecorator)
1515 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1516 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1517 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1518 // added for product variant only when we have vendor and product variants with core
1519 // variant. The suffix is not added for vendor-only or product-only module.
1520 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1521 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001522 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1523 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1524 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001525 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1526 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001527 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001528 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001529 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001530 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001531 if c.SplitPerApiLevel() {
1532 c.Properties.SubName += "." + c.SdkVersion()
1533 }
Inseob Kim64c43952019-08-26 16:52:35 +09001534 }
1535
Colin Crossca860ac2016-01-04 14:34:37 -08001536 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001537 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001538 moduleContextImpl: moduleContextImpl{
1539 mod: c,
1540 },
1541 }
1542 ctx.ctx = ctx
1543
Colin Crossf18e1102017-11-16 14:33:08 -08001544 deps := c.depsToPaths(ctx)
1545 if ctx.Failed() {
1546 return
1547 }
1548
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001549 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1550 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1551 }
1552
Colin Crossca860ac2016-01-04 14:34:37 -08001553 flags := Flags{
1554 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001555 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001556 }
Colin Crossca860ac2016-01-04 14:34:37 -08001557 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001558 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001559 }
1560 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001561 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001562 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001563 if c.stl != nil {
1564 flags = c.stl.flags(ctx, flags)
1565 }
Colin Cross16b23492016-01-06 14:41:07 -08001566 if c.sanitize != nil {
1567 flags = c.sanitize.flags(ctx, flags)
1568 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001569 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001570 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001571 }
Stephen Craneba090d12017-05-09 15:44:35 -07001572 if c.lto != nil {
1573 flags = c.lto.flags(ctx, flags)
1574 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001575 if c.pgo != nil {
1576 flags = c.pgo.flags(ctx, flags)
1577 }
Colin Crossca860ac2016-01-04 14:34:37 -08001578 for _, feature := range c.features {
1579 flags = feature.flags(ctx, flags)
1580 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001581 if ctx.Failed() {
1582 return
1583 }
1584
Colin Cross4af21ed2019-11-04 09:37:55 -08001585 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1586 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1587 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001588
Colin Cross4af21ed2019-11-04 09:37:55 -08001589 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001590
1591 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001592 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001593 }
1594 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001595 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001596 }
1597
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001598 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001599 // We need access to all the flags seen by a source file.
1600 if c.sabi != nil {
1601 flags = c.sabi.flags(ctx, flags)
1602 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001603
Colin Cross4af21ed2019-11-04 09:37:55 -08001604 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001605
Colin Crossca860ac2016-01-04 14:34:37 -08001606 // Optimization to reduce size of build.ninja
1607 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001608 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1609 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1610 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1611 flags.Local.CFlags = []string{"$cflags"}
1612 flags.Local.CppFlags = []string{"$cppflags"}
1613 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001614
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001615 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001616 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001617 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001618 if ctx.Failed() {
1619 return
1620 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001621 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001622 }
1623
Colin Crossca860ac2016-01-04 14:34:37 -08001624 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001625 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001626 if ctx.Failed() {
1627 return
1628 }
Colin Cross635c3b02016-05-18 15:37:25 -07001629 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001630
1631 // If a lib is directly included in any of the APEXes, unhide the stubs
1632 // variant having the latest version gets visible to make. In addition,
1633 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1634 // force anything in the make world to link against the stubs library.
1635 // (unless it is explicitly referenced via .bootstrap suffix or the
1636 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001637 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001638 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001639 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001640 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001641 c.Properties.HideFromMake = false // unhide
1642 // Note: this is still non-installable
1643 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001644
1645 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1646 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1647 if isSnapshotAware(ctx, c) {
1648 i.collectHeadersForSnapshot(ctx)
1649 }
1650 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001651 }
Colin Cross5049f022015-03-18 13:28:46 -07001652
Inseob Kim1f086e22019-05-09 13:29:15 +09001653 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001654 c.installer.install(ctx, c.outputFile.Path())
1655 if ctx.Failed() {
1656 return
Colin Crossca860ac2016-01-04 14:34:37 -08001657 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001658 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1659 // If the module has been specifically configure to not be installed then
1660 // skip the installation as otherwise it will break when running inside make
1661 // as the output path to install will not be specified. Not all uninstallable
1662 // modules can skip installation as some are needed for resolving make side
1663 // dependencies.
1664 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001665 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001666}
1667
Colin Cross0ea8ba82019-06-06 14:33:29 -07001668func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001669 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001670 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001671 }
Colin Crossca860ac2016-01-04 14:34:37 -08001672 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001673}
1674
Colin Crossca860ac2016-01-04 14:34:37 -08001675func (c *Module) begin(ctx BaseModuleContext) {
1676 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001677 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001678 }
Colin Crossca860ac2016-01-04 14:34:37 -08001679 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001680 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001681 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001682 if c.stl != nil {
1683 c.stl.begin(ctx)
1684 }
Colin Cross16b23492016-01-06 14:41:07 -08001685 if c.sanitize != nil {
1686 c.sanitize.begin(ctx)
1687 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001688 if c.coverage != nil {
1689 c.coverage.begin(ctx)
1690 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001691 if c.sabi != nil {
1692 c.sabi.begin(ctx)
1693 }
Justin Yun8effde42017-06-23 19:24:43 +09001694 if c.vndkdep != nil {
1695 c.vndkdep.begin(ctx)
1696 }
Stephen Craneba090d12017-05-09 15:44:35 -07001697 if c.lto != nil {
1698 c.lto.begin(ctx)
1699 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001700 if c.pgo != nil {
1701 c.pgo.begin(ctx)
1702 }
Colin Crossca860ac2016-01-04 14:34:37 -08001703 for _, feature := range c.features {
1704 feature.begin(ctx)
1705 }
Dan Albert92fe7402020-07-15 13:33:30 -07001706 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001707 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001708 if err != nil {
1709 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001710 c.Properties.Sdk_version = nil
1711 } else {
1712 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001713 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001714 }
Colin Crossca860ac2016-01-04 14:34:37 -08001715}
1716
Colin Cross37047f12016-12-13 17:06:13 -08001717func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001718 deps := Deps{}
1719
1720 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001721 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001722 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001723 // Add the PGO dependency (the clang_rt.profile runtime library), which
1724 // sometimes depends on symbols from libgcc, before libgcc gets added
1725 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001726 if c.pgo != nil {
1727 deps = c.pgo.deps(ctx, deps)
1728 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001729 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001730 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001731 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001732 if c.stl != nil {
1733 deps = c.stl.deps(ctx, deps)
1734 }
Colin Cross16b23492016-01-06 14:41:07 -08001735 if c.sanitize != nil {
1736 deps = c.sanitize.deps(ctx, deps)
1737 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001738 if c.coverage != nil {
1739 deps = c.coverage.deps(ctx, deps)
1740 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001741 if c.sabi != nil {
1742 deps = c.sabi.deps(ctx, deps)
1743 }
Justin Yun8effde42017-06-23 19:24:43 +09001744 if c.vndkdep != nil {
1745 deps = c.vndkdep.deps(ctx, deps)
1746 }
Stephen Craneba090d12017-05-09 15:44:35 -07001747 if c.lto != nil {
1748 deps = c.lto.deps(ctx, deps)
1749 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001750 for _, feature := range c.features {
1751 deps = feature.deps(ctx, deps)
1752 }
1753
Colin Crossb6715442017-10-24 11:13:31 -07001754 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1755 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1756 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1757 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1758 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1759 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001760 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001761
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001762 for _, lib := range deps.ReexportSharedLibHeaders {
1763 if !inList(lib, deps.SharedLibs) {
1764 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1765 }
1766 }
1767
1768 for _, lib := range deps.ReexportStaticLibHeaders {
1769 if !inList(lib, deps.StaticLibs) {
1770 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1771 }
1772 }
1773
Colin Cross5950f382016-12-13 12:50:57 -08001774 for _, lib := range deps.ReexportHeaderLibHeaders {
1775 if !inList(lib, deps.HeaderLibs) {
1776 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1777 }
1778 }
1779
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001780 for _, gen := range deps.ReexportGeneratedHeaders {
1781 if !inList(gen, deps.GeneratedHeaders) {
1782 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1783 }
1784 }
1785
Colin Crossc99deeb2016-04-11 15:06:20 -07001786 return deps
1787}
1788
Dan Albert7e9d2952016-08-04 13:02:36 -07001789func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001790 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001791 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001792 moduleContextImpl: moduleContextImpl{
1793 mod: c,
1794 },
1795 }
1796 ctx.ctx = ctx
1797
Colin Crossca860ac2016-01-04 14:34:37 -08001798 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001799}
1800
Jiyong Park7ed9de32018-10-15 22:25:07 +09001801// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001802func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001803 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1804 version := name[sharp+1:]
1805 libname := name[:sharp]
1806 return libname, version
1807 }
1808 return name, ""
1809}
1810
Dan Albert92fe7402020-07-15 13:33:30 -07001811func GetCrtVariations(ctx android.BottomUpMutatorContext,
1812 m LinkableInterface) []blueprint.Variation {
1813 if ctx.Os() != android.Android {
1814 return nil
1815 }
1816 if m.UseSdk() {
1817 return []blueprint.Variation{
1818 {Mutator: "sdk", Variation: "sdk"},
1819 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1820 }
1821 }
1822 return []blueprint.Variation{
1823 {Mutator: "sdk", Variation: ""},
1824 }
1825}
1826
Colin Cross1e676be2016-10-12 14:38:15 -07001827func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001828 if !c.Enabled() {
1829 return
1830 }
1831
Colin Cross37047f12016-12-13 17:06:13 -08001832 ctx := &depsContext{
1833 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001834 moduleContextImpl: moduleContextImpl{
1835 mod: c,
1836 },
1837 }
1838 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001839
Colin Crossc99deeb2016-04-11 15:06:20 -07001840 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001841
Dan Albert914449f2016-06-17 16:45:24 -07001842 variantNdkLibs := []string{}
1843 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001844 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001845 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001846 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001847 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001848 // 1. Name of an NDK library that refers to a prebuilt module.
1849 // For each of these, it adds the name of the prebuilt module (which will be in
1850 // prebuilts/ndk) to the list of nonvariant libs.
1851 // 2. Name of an NDK library that refers to an ndk_library module.
1852 // For each of these, it adds the name of the ndk_library module to the list of
1853 // variant libs.
1854 // 3. Anything else (so anything that isn't an NDK library).
1855 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001856 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001857 // The caller can then know to add the variantLibs dependencies differently from the
1858 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001859
Inseob Kim9516ee92019-05-09 10:56:13 +09001860 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001861 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1862
1863 rewriteVendorLibs := func(lib string) string {
1864 if isLlndkLibrary(lib, ctx.Config()) {
1865 return lib + llndkLibrarySuffix
1866 }
1867
1868 // only modules with BOARD_VNDK_VERSION uses snapshot.
1869 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1870 return lib
1871 }
1872
1873 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1874 return snapshot
1875 }
1876
1877 return lib
1878 }
1879
1880 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001881 variantLibs = []string{}
1882 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001883 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001884 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001885 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001886 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1887 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001888 } else if ctx.useVndk() {
1889 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001890 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001891 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001892 if actx.OtherModuleExists(vendorPublicLib) {
1893 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1894 } else {
1895 // This can happen if vendor_public_library module is defined in a
1896 // namespace that isn't visible to the current module. In that case,
1897 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001898 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001899 }
Dan Albert914449f2016-06-17 16:45:24 -07001900 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001901 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001902 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001903 }
1904 }
Dan Albert914449f2016-06-17 16:45:24 -07001905 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001906 }
1907
Inseob Kimeec88e12020-01-22 11:11:29 +09001908 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1909 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1910 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1911 if ctx.useVndk() {
1912 for idx, lib := range deps.RuntimeLibs {
1913 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1914 }
1915 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001916 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001917
Jiyong Park7e636d02019-01-28 16:16:54 +09001918 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001919 if c.linker != nil {
1920 if library, ok := c.linker.(*libraryDecorator); ok {
1921 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001922 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001923 }
1924 }
1925 }
1926
Inseob Kimeec88e12020-01-22 11:11:29 +09001927 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1928 // only modules with BOARD_VNDK_VERSION uses snapshot.
1929 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1930 return lib
1931 }
1932
1933 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1934 return snapshot
1935 }
1936
1937 return lib
1938 }
1939
1940 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001941 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001942 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001943 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001944 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001945 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001946
1947 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1948
Jiyong Park7e636d02019-01-28 16:16:54 +09001949 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001950 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001951 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001952 } else {
1953 actx.AddVariationDependencies(nil, depTag, lib)
1954 }
1955 }
1956
1957 if buildStubs {
1958 // Stubs lib does not have dependency to other static/shared libraries.
1959 // Don't proceed.
1960 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001961 }
Colin Cross5950f382016-12-13 12:50:57 -08001962
Inseob Kimc0907f12019-02-08 21:00:45 +09001963 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001964 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001965
Jiyong Park5d1598f2019-02-25 22:14:17 +09001966 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001967 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001968 if impl, ok := syspropImplLibraries[lib]; ok {
1969 lib = impl
1970 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001971
1972 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1973
Jiyong Park5d1598f2019-02-25 22:14:17 +09001974 actx.AddVariationDependencies([]blueprint.Variation{
1975 {Mutator: "link", Variation: "static"},
1976 }, depTag, lib)
1977 }
1978
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001979 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001980 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001981 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001982 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001983 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001984
1985 if impl, ok := syspropImplLibraries[lib]; ok {
1986 lib = impl
1987 }
1988
Inseob Kimeec88e12020-01-22 11:11:29 +09001989 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1990
Dan Willemsen59339a22018-07-22 21:18:45 -07001991 actx.AddVariationDependencies([]blueprint.Variation{
1992 {Mutator: "link", Variation: "static"},
1993 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001994 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001995
Jooyung Han75568392020-03-20 04:29:24 +09001996 // staticUnwinderDep is treated as staticDep for Q apexes
1997 // so that native libraries/binaries are linked with static unwinder
1998 // because Q libc doesn't have unwinder APIs
1999 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07002000 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002001 actx.AddVariationDependencies([]blueprint.Variation{
2002 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002003 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002004 }
2005
Inseob Kimeec88e12020-01-22 11:11:29 +09002006 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002007 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09002008 actx.AddVariationDependencies([]blueprint.Variation{
2009 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002010 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09002011 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002012
Colin Cross6e511a92020-07-27 21:26:48 -07002013 addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002014 var variations []blueprint.Variation
2015 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09002016 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002017 // Version is explicitly specified. i.e. libFoo#30
2018 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Colin Cross6e511a92020-07-27 21:26:48 -07002019 depTag.explicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09002020 }
Colin Crossd1f898e2020-08-18 18:35:15 -07002021 deps := actx.AddVariationDependencies(variations, depTag, name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002022
Jooyung Han03b51852020-02-26 22:45:42 +09002023 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002024 // The stubs library will be used when the depending module is built for APEX and
2025 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09002026 if version == "" && VersionVariantAvailable(c) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002027 if dep, ok := deps[0].(*Module); ok {
2028 for _, ver := range dep.AllStubsVersions() {
2029 // Note that depTag.ExplicitlyVersioned is false in this case.
2030 ctx.AddVariationDependencies([]blueprint.Variation{
2031 {Mutator: "link", Variation: "shared"},
2032 {Mutator: "version", Variation: ver},
2033 }, depTag, name)
2034 }
Jooyung Han03b51852020-02-26 22:45:42 +09002035 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002036 }
2037 }
2038
Jiyong Park7ed9de32018-10-15 22:25:07 +09002039 // shared lib names without the #version suffix
2040 var sharedLibNames []string
2041
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002042 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002043 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002044 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002045 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002046 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002047
2048 if impl, ok := syspropImplLibraries[lib]; ok {
2049 lib = impl
2050 }
2051
Jiyong Park73c54ee2019-10-22 20:31:18 +09002052 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002053 sharedLibNames = append(sharedLibNames, name)
2054
Jiyong Park25fc6a92018-11-18 18:02:45 +09002055 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002056 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002057
Jiyong Park7ed9de32018-10-15 22:25:07 +09002058 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002059 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002060 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2061 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2062 // linking against both the stubs lib and the non-stubs lib at the same time.
2063 continue
2064 }
Colin Cross6e511a92020-07-27 21:26:48 -07002065 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
2066 addSharedLibDependencies(depTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09002067 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002068
Dan Willemsen59339a22018-07-22 21:18:45 -07002069 actx.AddVariationDependencies([]blueprint.Variation{
2070 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002071 }, dataLibDepTag, deps.DataLibs...)
2072
2073 actx.AddVariationDependencies([]blueprint.Variation{
2074 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002075 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002076
Colin Cross68861832016-07-08 10:41:41 -07002077 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002078
2079 for _, gen := range deps.GeneratedHeaders {
2080 depTag := genHeaderDepTag
2081 if inList(gen, deps.ReexportGeneratedHeaders) {
2082 depTag = genHeaderExportDepTag
2083 }
2084 actx.AddDependency(c, depTag, gen)
2085 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002086
Colin Cross42d48b72018-08-29 14:10:52 -07002087 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002088
Inseob Kim1042d292020-06-01 23:23:05 +09002089 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2090
Dan Albert92fe7402020-07-15 13:33:30 -07002091 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07002092 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002093 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2094 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002095 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002096 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002097 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2098 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002099 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002100 if deps.LinkerFlagsFile != "" {
2101 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2102 }
2103 if deps.DynamicLinker != "" {
2104 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002105 }
Dan Albert914449f2016-06-17 16:45:24 -07002106
2107 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002108
2109 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002110 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002111 {Mutator: "ndk_api", Variation: version},
2112 {Mutator: "link", Variation: "shared"},
2113 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002114
2115 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002116 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002117 {Mutator: "ndk_api", Variation: version},
2118 {Mutator: "link", Variation: "shared"},
2119 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002120
2121 if vndkdep := c.vndkdep; vndkdep != nil {
2122 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002123 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002124 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002125 {Mutator: "link", Variation: "shared"},
2126 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002127 }
2128 }
Colin Cross6362e272015-10-29 15:25:03 -07002129}
Colin Cross21b9a242015-03-24 14:15:58 -07002130
Colin Crosse40b4ea2018-10-02 22:25:58 -07002131func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002132 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2133 c.beginMutator(ctx)
2134 }
2135}
2136
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002137// Whether a module can link to another module, taking into
2138// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002139func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2140 tag blueprint.DependencyTag) {
2141
2142 switch t := tag.(type) {
2143 case dependencyTag:
2144 if t != vndkExtDepTag {
2145 return
2146 }
2147 case libraryDependencyTag:
2148 default:
2149 return
2150 }
2151
Ivan Lozano52767be2019-10-18 14:49:46 -07002152 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002153 // Host code is not restricted
2154 return
2155 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002156
2157 // VNDK is cc.Module supported only for now.
2158 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002159 // Though vendor code is limited by the vendor mutator,
2160 // each vendor-available module needs to check
2161 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002162 if ccTo, ok := to.(*Module); ok {
2163 if ccFrom.vndkdep != nil {
2164 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2165 }
2166 } else {
2167 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002168 }
2169 return
2170 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002171 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002172 // Platform code can link to anything
2173 return
2174 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002175 if from.InRamdisk() {
2176 // Ramdisk code is not NDK
2177 return
2178 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002179 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002180 // Recovery code is not NDK
2181 return
2182 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002183 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002184 // These are always allowed
2185 return
2186 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002187 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002188 // These are allowed, but they don't set sdk_version
2189 return
2190 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002191 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002192 // These aren't real libraries, but are the stub shared libraries that are included in
2193 // the NDK.
2194 return
2195 }
Logan Chien834b9a62019-01-14 15:39:03 +08002196
Ivan Lozano52767be2019-10-18 14:49:46 -07002197 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002198 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2199 // to link to libc++ (non-NDK and without sdk_version).
2200 return
2201 }
2202
Ivan Lozano52767be2019-10-18 14:49:46 -07002203 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002204 // NDK code linking to platform code is never okay.
2205 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002206 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002207 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002208 }
2209
2210 // At this point we know we have two NDK libraries, but we need to
2211 // check that we're not linking against anything built against a higher
2212 // API level, as it is only valid to link against older or equivalent
2213 // APIs.
2214
Inseob Kim01a28722018-04-11 09:48:45 +09002215 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002216 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002217 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002218 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002219 // Current can't be linked against by anything else.
2220 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002221 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002222 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002223 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002224 if err != nil {
2225 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002226 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002227 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002228 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002229 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002230 if err != nil {
2231 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002232 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002233 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002234 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002235
Inseob Kim01a28722018-04-11 09:48:45 +09002236 if toApi > fromApi {
2237 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002238 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002239 }
2240 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002241 }
Dan Albert202fe492017-12-15 13:56:59 -08002242
2243 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002244 fromStl := from.SelectedStl()
2245 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002246 if fromStl == "" || toStl == "" {
2247 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002248 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002249 // We can be permissive with the system "STL" since it is only the C++
2250 // ABI layer, but in the future we should make sure that everyone is
2251 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002252 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002253 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002254 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2255 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002256 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002257}
2258
Jiyong Park5fb8c102018-04-09 12:03:06 +09002259// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002260// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2261// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002262// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002263func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2264 check := func(child, parent android.Module) bool {
2265 to, ok := child.(*Module)
2266 if !ok {
2267 // follow thru cc.Defaults, etc.
2268 return true
2269 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002270
Jooyung Hana70f0672019-01-18 15:20:43 +09002271 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2272 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002273 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002274
2275 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002276 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002277 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002278 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002279
Jooyung Han0302a842019-10-30 18:43:49 +09002280 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002281 return false
2282 }
2283
2284 var stringPath []string
2285 for _, m := range ctx.GetWalkPath() {
2286 stringPath = append(stringPath, m.Name())
2287 }
2288 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2289 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2290 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2291 return false
2292 }
2293 if module, ok := ctx.Module().(*Module); ok {
2294 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002295 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002296 ctx.WalkDeps(check)
2297 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002298 }
2299 }
2300}
2301
Colin Crossc99deeb2016-04-11 15:06:20 -07002302// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002303func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002304 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002305
Ivan Lozano183a3212019-10-18 14:18:45 -07002306 directStaticDeps := []LinkableInterface{}
2307 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002308
Inseob Kim69378442019-06-03 19:10:47 +09002309 reexportExporter := func(exporter exportedFlagsProducer) {
2310 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2311 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2312 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2313 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002314 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002315 }
2316
Jooyung Hande34d232020-07-23 13:04:15 +09002317 // For the dependency from platform to apex, use the latest stubs
2318 c.apexSdkVersion = android.FutureApiLevel
2319 if !c.IsForPlatform() {
Dan Albertc8060532020-07-22 22:32:17 -07002320 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002321 }
2322
2323 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2324 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2325 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2326 // (b/144430859)
2327 c.apexSdkVersion = android.FutureApiLevel
2328 }
2329
Colin Crossd11fcda2017-10-23 17:59:01 -07002330 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002331 depName := ctx.OtherModuleName(dep)
2332 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002333
Ivan Lozano52767be2019-10-18 14:49:46 -07002334 ccDep, ok := dep.(LinkableInterface)
2335 if !ok {
2336
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002337 // handling for a few module types that aren't cc Module but that are also supported
2338 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002339 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002340 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002341 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2342 genRule.GeneratedSourceFiles()...)
2343 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002344 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002345 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002346 // Support exported headers from a generated_sources dependency
2347 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002348 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002349 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002350 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002351 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002352 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002353 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002354 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002355 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002356 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2357 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002358 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002359 // 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 +09002360 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002361
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002362 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002363 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002364 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002365 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002366 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002367 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002368 files := genRule.GeneratedSourceFiles()
2369 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002370 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002371 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002372 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 -07002373 }
2374 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002375 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002376 }
Colin Crossca860ac2016-01-04 14:34:37 -08002377 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002378 return
2379 }
2380
Colin Crossfe17f6f2019-03-28 19:30:56 -07002381 if depTag == android.ProtoPluginDepTag {
2382 return
2383 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002384 if depTag == llndkImplDep {
2385 return
2386 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002387
Colin Crossd11fcda2017-10-23 17:59:01 -07002388 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002389 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2390 return
2391 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002392 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002393 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2394 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002395 return
2396 }
2397
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002398 // re-exporting flags
2399 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002400 // reusing objects only make sense for cc.Modules.
2401 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002402 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002403 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002404 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002405 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002406 return
2407 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002408 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002409
Jiyong Parke4bb9862019-02-01 00:31:10 +09002410 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002411 // staticVariants are a cc.Module specific concept.
2412 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002413 c.staticVariant = ccDep
2414 return
2415 }
2416 }
2417
Colin Cross6e511a92020-07-27 21:26:48 -07002418 checkLinkType(ctx, c, ccDep, depTag)
2419
2420 linkFile := ccDep.OutputFile()
2421
2422 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2423 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002424 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002425 return
2426 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002427
Colin Cross6e511a92020-07-27 21:26:48 -07002428 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002429 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002430 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Colin Crossaede88c2020-08-11 12:17:01 -07002431 depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002432 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002433
2434 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002435 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002436 // Always respect dependency to the versioned stubs (i.e. libX#10)
2437 useThisDep = true
2438 } else if !depHasStubs {
2439 // Use non-stub variant if that is the only choice
2440 // (i.e. depending on a lib without stubs.version property)
2441 useThisDep = true
2442 } else if c.IsForPlatform() {
2443 // If not building for APEX, use stubs only when it is from
2444 // an APEX (and not from platform)
2445 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002446 if c.bootstrap() {
2447 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002448 // always link to non-stub variant
2449 useThisDep = !depIsStubs
2450 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002451 for _, testFor := range c.TestFor() {
2452 // Another exception: if this module is bundled with an APEX, then
2453 // it is linked with the non-stub variant of a module in the APEX
2454 // as if this is part of the APEX.
2455 if android.DirectlyInApex(testFor, depName) {
2456 useThisDep = !depIsStubs
2457 break
2458 }
2459 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002460 } else {
Colin Crossaede88c2020-08-11 12:17:01 -07002461 // If building for APEX, use stubs when the parent is in any APEX that
2462 // the child is not in.
2463 useThisDep = (depInSameApexes != depIsStubs)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002464 }
2465
Jooyung Han03b51852020-02-26 22:45:42 +09002466 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002467 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Dan Albertc8060532020-07-22 22:32:17 -07002468 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion.FinalOrFutureInt())
Jooyung Han03b51852020-02-26 22:45:42 +09002469 if err != nil {
2470 ctx.OtherModuleErrorf(dep, err.Error())
2471 return
2472 }
2473 if versionToUse != ccDep.StubsVersion() {
2474 useThisDep = false
2475 }
2476 }
2477
Jiyong Park25fc6a92018-11-18 18:02:45 +09002478 if !useThisDep {
2479 return // stop processing this dep
2480 }
2481 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002482 if c.UseVndk() {
2483 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2484 // by default, use current version of LLNDK
2485 versionToUse := ""
Colin Crossd1f898e2020-08-18 18:35:15 -07002486 versions := m.AllStubsVersions()
Colin Crosse07f2312020-08-13 11:24:56 -07002487 if c.ApexVariationName() != "" && len(versions) > 0 {
Jooyung Han61b66e92020-03-21 14:21:46 +00002488 // if this is for use_vendor apex && dep has stubsVersions
2489 // apply the same rule of apex sdk enforcement to choose right version
2490 var err error
Dan Albertc8060532020-07-22 22:32:17 -07002491 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion.FinalOrFutureInt())
Jooyung Han61b66e92020-03-21 14:21:46 +00002492 if err != nil {
2493 ctx.OtherModuleErrorf(dep, err.Error())
2494 return
2495 }
2496 }
2497 if versionToUse != ccDep.StubsVersion() {
2498 return
2499 }
2500 }
2501 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002502
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002503 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2504
Ivan Lozano52767be2019-10-18 14:49:46 -07002505 // Exporting flags only makes sense for cc.Modules
2506 if _, ok := ccDep.(*Module); ok {
2507 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002508 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002509 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002510 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002511
Colin Cross6e511a92020-07-27 21:26:48 -07002512 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002513 reexportExporter(i)
2514 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2515 // Re-exported shared library headers must be included as well since they can help us with type information
2516 // about template instantiations (instantiated from their headers).
2517 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2518 // scripts.
2519 c.sabi.Properties.ReexportedIncludes = append(
2520 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2521 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002522 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002523 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002524
Colin Cross6e511a92020-07-27 21:26:48 -07002525 var ptr *android.Paths
2526 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002527
Colin Cross6e511a92020-07-27 21:26:48 -07002528 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002529
Colin Cross6e511a92020-07-27 21:26:48 -07002530 switch {
2531 case libDepTag.header():
2532 // nothing
2533 case libDepTag.shared():
2534 ptr = &depPaths.SharedLibs
2535 switch libDepTag.Order {
2536 case earlyLibraryDependency:
2537 ptr = &depPaths.EarlySharedLibs
2538 depPtr = &depPaths.EarlySharedLibsDeps
2539 case normalLibraryDependency:
2540 ptr = &depPaths.SharedLibs
2541 depPtr = &depPaths.SharedLibsDeps
2542 directSharedDeps = append(directSharedDeps, ccDep)
2543 case lateLibraryDependency:
2544 ptr = &depPaths.LateSharedLibs
2545 depPtr = &depPaths.LateSharedLibsDeps
2546 default:
2547 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002548 }
Colin Cross6e511a92020-07-27 21:26:48 -07002549 depFile = ccDep.Toc()
2550 case libDepTag.static():
2551 if libDepTag.wholeStatic {
2552 ptr = &depPaths.WholeStaticLibs
2553 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2554 ctx.ModuleErrorf("module %q not a static library", depName)
2555 return
Inseob Kim752edec2020-03-14 01:30:34 +09002556 }
2557
Colin Cross6e511a92020-07-27 21:26:48 -07002558 // Because the static library objects are included, this only makes sense
2559 // in the context of proper cc.Modules.
2560 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2561 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2562 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2563 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2564 for i := range missingDeps {
2565 missingDeps[i] += postfix
2566 }
2567 ctx.AddMissingDependencies(missingDeps)
2568 }
2569 if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
2570 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
2571 } else {
2572 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2573 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002574 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002575 ctx.ModuleErrorf(
2576 "non-cc.Modules cannot be included as whole static libraries.", depName)
2577 return
2578 }
2579
2580 } else {
2581 switch libDepTag.Order {
2582 case earlyLibraryDependency:
2583 panic(fmt.Errorf("early static libs not suppported"))
2584 case normalLibraryDependency:
2585 // static dependencies will be handled separately so they can be ordered
2586 // using transitive dependencies.
2587 ptr = nil
2588 directStaticDeps = append(directStaticDeps, ccDep)
2589 case lateLibraryDependency:
2590 ptr = &depPaths.LateStaticLibs
2591 default:
2592 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002593 }
2594 }
2595 }
2596
Colin Cross6e511a92020-07-27 21:26:48 -07002597 if libDepTag.static() && !libDepTag.wholeStatic {
2598 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2599 ctx.ModuleErrorf("module %q not a static library", depName)
2600 return
2601 }
Logan Chien43d34c32017-12-20 01:17:32 +08002602
Colin Cross6e511a92020-07-27 21:26:48 -07002603 // When combining coverage files for shared libraries and executables, coverage files
2604 // in static libraries act as if they were whole static libraries. The same goes for
2605 // source based Abi dump files.
2606 if c, ok := ccDep.(*Module); ok {
2607 staticLib := c.linker.(libraryInterface)
2608 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2609 staticLib.objs().coverageFiles...)
2610 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2611 staticLib.objs().sAbiDumpFiles...)
2612 } else if c, ok := ccDep.(LinkableInterface); ok {
2613 // Handle non-CC modules here
2614 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2615 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002616 }
2617 }
2618
Colin Cross6e511a92020-07-27 21:26:48 -07002619 if ptr != nil {
2620 if !linkFile.Valid() {
2621 if !ctx.Config().AllowMissingDependencies() {
2622 ctx.ModuleErrorf("module %q missing output file", depName)
2623 } else {
2624 ctx.AddMissingDependencies([]string{depName})
2625 }
2626 return
2627 }
2628 *ptr = append(*ptr, linkFile.Path())
2629 }
2630
2631 if depPtr != nil {
2632 dep := depFile
2633 if !dep.Valid() {
2634 dep = linkFile
2635 }
2636 *depPtr = append(*depPtr, dep.Path())
2637 }
2638
2639 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2640 switch {
2641 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002642 c.Properties.AndroidMkHeaderLibs = append(
2643 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002644 case libDepTag.shared():
2645 if ccDep.CcLibrary() {
2646 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2647 // Add the dependency to the APEX(es) providing the library so that
2648 // m <module> can trigger building the APEXes as well.
2649 for _, an := range android.GetApexesForModule(depName) {
2650 c.Properties.ApexesProvidingSharedLibs = append(
2651 c.Properties.ApexesProvidingSharedLibs, an)
2652 }
2653 }
2654 }
2655
2656 // Note: the order of libs in this list is not important because
2657 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002658 c.Properties.AndroidMkSharedLibs = append(
2659 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002660 // Record baseLibName for snapshots.
2661 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2662 case libDepTag.static():
2663 if libDepTag.wholeStatic {
2664 c.Properties.AndroidMkWholeStaticLibs = append(
2665 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2666 } else {
2667 c.Properties.AndroidMkStaticLibs = append(
2668 c.Properties.AndroidMkStaticLibs, makeLibName)
2669 }
2670 }
2671 } else {
2672 switch depTag {
2673 case runtimeDepTag:
2674 c.Properties.AndroidMkRuntimeLibs = append(
2675 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2676 // Record baseLibName for snapshots.
2677 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2678 case objDepTag:
2679 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2680 case CrtBeginDepTag:
2681 depPaths.CrtBegin = linkFile
2682 case CrtEndDepTag:
2683 depPaths.CrtEnd = linkFile
2684 case dynamicLinkerDepTag:
2685 depPaths.DynamicLinker = linkFile
2686 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002687 }
Colin Crossca860ac2016-01-04 14:34:37 -08002688 })
2689
Jeff Gaston294356f2017-09-27 17:05:30 -07002690 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002691 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002692
Colin Crossdd84e052017-05-17 13:44:16 -07002693 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002694 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002695 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2696 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002697 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002698 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2699 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002700 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002701 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002702 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002703
2704 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002705 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002706 }
Colin Crossdd84e052017-05-17 13:44:16 -07002707
Colin Crossca860ac2016-01-04 14:34:37 -08002708 return depPaths
2709}
2710
Colin Cross6e511a92020-07-27 21:26:48 -07002711// baseLibName trims known prefixes and suffixes
2712func baseLibName(depName string) string {
2713 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2714 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2715 libName = strings.TrimPrefix(libName, "prebuilt_")
2716 return libName
2717}
2718
2719func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2720 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2721 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2722
2723 libName := baseLibName(depName)
2724 isLLndk := isLlndkLibrary(libName, ctx.Config())
2725 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2726 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2727
2728 if c, ok := ccDep.(*Module); ok {
2729 // Use base module name for snapshots when exporting to Makefile.
2730 if c.isSnapshotPrebuilt() {
2731 baseName := c.BaseModuleName()
2732
2733 if c.IsVndk() {
2734 return baseName + ".vendor"
2735 }
2736
2737 if vendorSuffixModules[baseName] {
2738 return baseName + ".vendor"
2739 } else {
2740 return baseName
2741 }
2742 }
2743 }
2744
2745 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2746 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2747 // core module instead.
2748 return libName
2749 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2750 // The vendor module in Make will have been renamed to not conflict with the core
2751 // module, so update the dependency name here accordingly.
2752 return libName + c.getNameSuffixWithVndkVersion(ctx)
2753 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2754 return libName + vendorPublicLibrarySuffix
2755 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2756 return libName + ramdiskSuffix
2757 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2758 return libName + recoverySuffix
2759 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2760 return libName + nativeBridgeSuffix
2761 } else {
2762 return libName
2763 }
2764}
2765
Colin Crossca860ac2016-01-04 14:34:37 -08002766func (c *Module) InstallInData() bool {
2767 if c.installer == nil {
2768 return false
2769 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002770 return c.installer.inData()
2771}
2772
2773func (c *Module) InstallInSanitizerDir() bool {
2774 if c.installer == nil {
2775 return false
2776 }
2777 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002778 return true
2779 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002780 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002781}
2782
Yifan Hong1b3348d2020-01-21 15:53:22 -08002783func (c *Module) InstallInRamdisk() bool {
2784 return c.InRamdisk()
2785}
2786
Jiyong Parkf9332f12018-02-01 00:54:12 +09002787func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002788 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002789}
2790
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002791func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002792 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002793 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002794 return
2795 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002796 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002797}
2798
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002799func (c *Module) HostToolPath() android.OptionalPath {
2800 if c.installer == nil {
2801 return android.OptionalPath{}
2802 }
2803 return c.installer.hostToolPath()
2804}
2805
Nan Zhangd4e641b2017-07-12 12:55:28 -07002806func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2807 return c.outputFile
2808}
2809
Colin Cross41955e82019-05-29 14:40:35 -07002810func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2811 switch tag {
2812 case "":
2813 if c.outputFile.Valid() {
2814 return android.Paths{c.outputFile.Path()}, nil
2815 }
2816 return android.Paths{}, nil
2817 default:
2818 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002819 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002820}
2821
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002822func (c *Module) static() bool {
2823 if static, ok := c.linker.(interface {
2824 static() bool
2825 }); ok {
2826 return static.static()
2827 }
2828 return false
2829}
2830
Jiyong Park379de2f2018-12-19 02:47:14 +09002831func (c *Module) staticBinary() bool {
2832 if static, ok := c.linker.(interface {
2833 staticBinary() bool
2834 }); ok {
2835 return static.staticBinary()
2836 }
2837 return false
2838}
2839
Jiyong Park1d1119f2019-07-29 21:27:18 +09002840func (c *Module) header() bool {
2841 if h, ok := c.linker.(interface {
2842 header() bool
2843 }); ok {
2844 return h.header()
2845 }
2846 return false
2847}
2848
Inseob Kim7f283f42020-06-01 21:53:49 +09002849func (c *Module) binary() bool {
2850 if b, ok := c.linker.(interface {
2851 binary() bool
2852 }); ok {
2853 return b.binary()
2854 }
2855 return false
2856}
2857
Inseob Kim1042d292020-06-01 23:23:05 +09002858func (c *Module) object() bool {
2859 if o, ok := c.linker.(interface {
2860 object() bool
2861 }); ok {
2862 return o.object()
2863 }
2864 return false
2865}
2866
Jooyung Han38002912019-05-16 04:01:54 +09002867func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002868 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002869 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2870 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002871 return "native:vndk"
2872 }
Jooyung Han38002912019-05-16 04:01:54 +09002873 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002874 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002875 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002876 if Bool(c.VendorProperties.Vendor_available) {
2877 return "native:vndk"
2878 }
2879 return "native:vndk_private"
2880 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002881 if c.inProduct() {
2882 return "native:product"
2883 }
Jooyung Han38002912019-05-16 04:01:54 +09002884 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002885 } else if c.InRamdisk() {
2886 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002887 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002888 return "native:recovery"
2889 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2890 return "native:ndk:none:none"
2891 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2892 //family, link := getNdkStlFamilyAndLinkType(c)
2893 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002894 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002895 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002896 } else {
2897 return "native:platform"
2898 }
2899}
2900
Jiyong Park9d452992018-10-03 00:38:19 +09002901// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002902// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002903func (c *Module) IsInstallableToApex() bool {
2904 if shared, ok := c.linker.(interface {
2905 shared() bool
2906 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002907 // Stub libs and prebuilt libs in a versioned SDK are not
2908 // installable to APEX even though they are shared libs.
2909 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002910 } else if _, ok := c.linker.(testPerSrc); ok {
2911 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002912 }
2913 return false
2914}
2915
Jiyong Parka90ca002019-10-07 15:47:24 +09002916func (c *Module) AvailableFor(what string) bool {
2917 if linker, ok := c.linker.(interface {
2918 availableFor(string) bool
2919 }); ok {
2920 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2921 } else {
2922 return c.ApexModuleBase.AvailableFor(what)
2923 }
2924}
2925
Jiyong Park62304bb2020-04-13 16:19:48 +09002926func (c *Module) TestFor() []string {
2927 if test, ok := c.linker.(interface {
2928 testFor() []string
2929 }); ok {
2930 return test.testFor()
2931 } else {
2932 return c.ApexModuleBase.TestFor()
2933 }
2934}
2935
Colin Crossaede88c2020-08-11 12:17:01 -07002936func (c *Module) UniqueApexVariations() bool {
2937 if u, ok := c.compiler.(interface {
2938 uniqueApexVariations() bool
2939 }); ok {
2940 return u.uniqueApexVariations()
2941 } else {
2942 return false
2943 }
2944}
2945
Paul Duffin0cb37b92020-03-04 14:52:46 +00002946// Return true if the module is ever installable.
2947func (c *Module) EverInstallable() bool {
2948 return c.installer != nil &&
2949 // Check to see whether the module is actually ever installable.
2950 c.installer.everInstallable()
2951}
2952
Inseob Kim1f086e22019-05-09 13:29:15 +09002953func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002954 ret := c.EverInstallable() &&
2955 // Check to see whether the module has been configured to not be installed.
2956 proptools.BoolDefault(c.Properties.Installable, true) &&
2957 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002958
2959 // The platform variant doesn't need further condition. Apex variants however might not
2960 // be installable because it will likely to be included in the APEX and won't appear
2961 // in the system partition.
2962 if c.IsForPlatform() {
2963 return ret
2964 }
2965
2966 // Special case for modules that are configured to be installed to /data, which includes
2967 // test modules. For these modules, both APEX and non-APEX variants are considered as
2968 // installable. This is because even the APEX variants won't be included in the APEX, but
2969 // will anyway be installed to /data/*.
2970 // See b/146995717
2971 if c.InstallInData() {
2972 return ret
2973 }
2974
2975 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002976}
2977
Logan Chien41eabe62019-04-10 13:33:58 +08002978func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2979 if c.linker != nil {
2980 if library, ok := c.linker.(*libraryDecorator); ok {
2981 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2982 }
2983 }
2984}
2985
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002986func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002987 depTag := ctx.OtherModuleDependencyTag(dep)
2988 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2989
2990 if cc, ok := dep.(*Module); ok {
2991 if cc.HasStubsVariants() {
2992 if isLibDepTag && libDepTag.shared() {
2993 // dynamic dep to a stubs lib crosses APEX boundary
2994 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002995 }
Colin Cross6e511a92020-07-27 21:26:48 -07002996 if IsRuntimeDepTag(depTag) {
2997 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002998 return false
2999 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003000 }
Colin Crossaac32222020-07-29 12:51:56 -07003001 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07003002 // shared_lib dependency from a static lib is considered as crossing
3003 // the APEX boundary because the dependency doesn't actually is
3004 // linked; the dependency is used only during the compilation phase.
3005 return false
3006 }
3007 }
3008 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09003009 // We don't track beyond LLNDK
3010 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003011 }
3012 return true
3013}
3014
Dan Albertc8060532020-07-22 22:32:17 -07003015func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3016 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003017 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3018 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3019 return nil
3020 }
3021 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3022 if c.ToolchainLibrary() {
3023 return nil
3024 }
3025 // We don't check for prebuilt modules
3026 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3027 return nil
3028 }
3029 minSdkVersion := c.MinSdkVersion()
3030 if minSdkVersion == "apex_inherit" {
3031 return nil
3032 }
3033 if minSdkVersion == "" {
3034 // JNI libs within APK-in-APEX fall into here
3035 // Those are okay to set sdk_version instead
3036 // We don't have to check if this is a SDK variant because
3037 // non-SDK variant resets sdk_version, which works too.
3038 minSdkVersion = c.SdkVersion()
3039 }
Dan Albertc8060532020-07-22 22:32:17 -07003040 if minSdkVersion == "" {
3041 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3042 }
3043 // Not using nativeApiLevelFromUser because the context here is not
3044 // necessarily a native context.
3045 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003046 if err != nil {
3047 return err
3048 }
Dan Albertc8060532020-07-22 22:32:17 -07003049
3050 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003051 return fmt.Errorf("newer SDK(%v)", ver)
3052 }
3053 return nil
3054}
3055
Colin Cross2ba19d92015-05-07 15:44:20 -07003056//
Colin Crosscfad1192015-11-02 16:43:11 -08003057// Defaults
3058//
Colin Crossca860ac2016-01-04 14:34:37 -08003059type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003060 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003061 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003062 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003063}
3064
Patrice Arrudac249c712019-03-19 17:00:29 -07003065// cc_defaults provides a set of properties that can be inherited by other cc
3066// modules. A module can use the properties from a cc_defaults using
3067// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3068// merged (when possible) by prepending the default module's values to the
3069// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003070func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003071 return DefaultsFactory()
3072}
3073
Colin Cross36242852017-06-23 15:06:31 -07003074func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003075 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003076
Colin Cross36242852017-06-23 15:06:31 -07003077 module.AddProperties(props...)
3078 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003079 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003080 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003081 &BaseCompilerProperties{},
3082 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003083 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003084 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003085 &StaticProperties{},
3086 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003087 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003088 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003089 &TestProperties{},
3090 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003091 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003092 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003093 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003094 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003095 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003096 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003097 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003098 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003099 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003100 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003101 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003102 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003103 &android.ProtoProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -04003104 // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
3105 &RustBindgenClangProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003106 )
Colin Crosscfad1192015-11-02 16:43:11 -08003107
Jooyung Hancc372c52019-09-25 15:18:44 +09003108 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003109
3110 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003111}
3112
Jiyong Park6a43f042017-10-12 23:05:00 +09003113func squashVendorSrcs(m *Module) {
3114 if lib, ok := m.compiler.(*libraryDecorator); ok {
3115 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3116 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3117
3118 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3119 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003120
3121 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3122 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003123 }
3124}
3125
Jiyong Parkf9332f12018-02-01 00:54:12 +09003126func squashRecoverySrcs(m *Module) {
3127 if lib, ok := m.compiler.(*libraryDecorator); ok {
3128 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3129 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3130
3131 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3132 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003133
3134 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3135 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003136 }
3137}
3138
Jiyong Park2286afd2020-06-16 21:58:53 +09003139func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003140 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003141}
3142
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003143func kytheExtractAllFactory() android.Singleton {
3144 return &kytheExtractAllSingleton{}
3145}
3146
3147type kytheExtractAllSingleton struct {
3148}
3149
3150func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3151 var xrefTargets android.Paths
3152 ctx.VisitAllModules(func(module android.Module) {
3153 if ccModule, ok := module.(xref); ok {
3154 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3155 }
3156 })
3157 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3158 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003159 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003160 }
3161}
3162
Colin Cross06a931b2015-10-28 17:23:31 -07003163var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003164var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003165var BoolPtr = proptools.BoolPtr
3166var String = proptools.String
3167var StringPtr = proptools.StringPtr