blob: fb78b2073c5431e2bb7926e5a26c79aedcc6c17e [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
Jooyung Hanccce2f22020-03-07 03:45:53 +0900357 apexSdkVersion() int
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
618 apexSdkVersion int
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 {
633 return stub.properties.ApiLevel
634 }
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
Colin Crossa9d8bee2018-10-02 13:59:46 -0700953 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700954 // Windows builds always prefer 32-bit
955 return class == android.HostCross
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
Jooyung Hanccce2f22020-03-07 03:45:53 +09001331func (ctx *moduleContextImpl) apexSdkVersion() int {
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 Albertf5415d72017-08-17 16:19:59 -07001707 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001708 if err != nil {
1709 ctx.PropertyErrorf("sdk_version", err.Error())
1710 }
Nan Zhang0007d812017-11-07 10:57:05 -08001711 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001712 }
Colin Crossca860ac2016-01-04 14:34:37 -08001713}
1714
Colin Cross37047f12016-12-13 17:06:13 -08001715func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001716 deps := Deps{}
1717
1718 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001719 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001720 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001721 // Add the PGO dependency (the clang_rt.profile runtime library), which
1722 // sometimes depends on symbols from libgcc, before libgcc gets added
1723 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001724 if c.pgo != nil {
1725 deps = c.pgo.deps(ctx, deps)
1726 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001727 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001728 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001729 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001730 if c.stl != nil {
1731 deps = c.stl.deps(ctx, deps)
1732 }
Colin Cross16b23492016-01-06 14:41:07 -08001733 if c.sanitize != nil {
1734 deps = c.sanitize.deps(ctx, deps)
1735 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001736 if c.coverage != nil {
1737 deps = c.coverage.deps(ctx, deps)
1738 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001739 if c.sabi != nil {
1740 deps = c.sabi.deps(ctx, deps)
1741 }
Justin Yun8effde42017-06-23 19:24:43 +09001742 if c.vndkdep != nil {
1743 deps = c.vndkdep.deps(ctx, deps)
1744 }
Stephen Craneba090d12017-05-09 15:44:35 -07001745 if c.lto != nil {
1746 deps = c.lto.deps(ctx, deps)
1747 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001748 for _, feature := range c.features {
1749 deps = feature.deps(ctx, deps)
1750 }
1751
Colin Crossb6715442017-10-24 11:13:31 -07001752 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1753 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1754 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1755 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1756 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1757 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001758 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001759
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001760 for _, lib := range deps.ReexportSharedLibHeaders {
1761 if !inList(lib, deps.SharedLibs) {
1762 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1763 }
1764 }
1765
1766 for _, lib := range deps.ReexportStaticLibHeaders {
1767 if !inList(lib, deps.StaticLibs) {
1768 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1769 }
1770 }
1771
Colin Cross5950f382016-12-13 12:50:57 -08001772 for _, lib := range deps.ReexportHeaderLibHeaders {
1773 if !inList(lib, deps.HeaderLibs) {
1774 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1775 }
1776 }
1777
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001778 for _, gen := range deps.ReexportGeneratedHeaders {
1779 if !inList(gen, deps.GeneratedHeaders) {
1780 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1781 }
1782 }
1783
Colin Crossc99deeb2016-04-11 15:06:20 -07001784 return deps
1785}
1786
Dan Albert7e9d2952016-08-04 13:02:36 -07001787func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001788 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001789 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001790 moduleContextImpl: moduleContextImpl{
1791 mod: c,
1792 },
1793 }
1794 ctx.ctx = ctx
1795
Colin Crossca860ac2016-01-04 14:34:37 -08001796 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001797}
1798
Jiyong Park7ed9de32018-10-15 22:25:07 +09001799// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001800func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001801 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1802 version := name[sharp+1:]
1803 libname := name[:sharp]
1804 return libname, version
1805 }
1806 return name, ""
1807}
1808
Dan Albert92fe7402020-07-15 13:33:30 -07001809func GetCrtVariations(ctx android.BottomUpMutatorContext,
1810 m LinkableInterface) []blueprint.Variation {
1811 if ctx.Os() != android.Android {
1812 return nil
1813 }
1814 if m.UseSdk() {
1815 return []blueprint.Variation{
1816 {Mutator: "sdk", Variation: "sdk"},
1817 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1818 }
1819 }
1820 return []blueprint.Variation{
1821 {Mutator: "sdk", Variation: ""},
1822 }
1823}
1824
Colin Cross1e676be2016-10-12 14:38:15 -07001825func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001826 if !c.Enabled() {
1827 return
1828 }
1829
Colin Cross37047f12016-12-13 17:06:13 -08001830 ctx := &depsContext{
1831 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001832 moduleContextImpl: moduleContextImpl{
1833 mod: c,
1834 },
1835 }
1836 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001837
Colin Crossc99deeb2016-04-11 15:06:20 -07001838 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001839
Dan Albert914449f2016-06-17 16:45:24 -07001840 variantNdkLibs := []string{}
1841 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001842 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001843 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001844 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001845 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001846 // 1. Name of an NDK library that refers to a prebuilt module.
1847 // For each of these, it adds the name of the prebuilt module (which will be in
1848 // prebuilts/ndk) to the list of nonvariant libs.
1849 // 2. Name of an NDK library that refers to an ndk_library module.
1850 // For each of these, it adds the name of the ndk_library module to the list of
1851 // variant libs.
1852 // 3. Anything else (so anything that isn't an NDK library).
1853 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001854 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001855 // The caller can then know to add the variantLibs dependencies differently from the
1856 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001857
Inseob Kim9516ee92019-05-09 10:56:13 +09001858 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001859 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1860
1861 rewriteVendorLibs := func(lib string) string {
1862 if isLlndkLibrary(lib, ctx.Config()) {
1863 return lib + llndkLibrarySuffix
1864 }
1865
1866 // only modules with BOARD_VNDK_VERSION uses snapshot.
1867 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1868 return lib
1869 }
1870
1871 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1872 return snapshot
1873 }
1874
1875 return lib
1876 }
1877
1878 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001879 variantLibs = []string{}
1880 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001881 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001882 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001883 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001884 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1885 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001886 } else if ctx.useVndk() {
1887 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001888 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001889 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001890 if actx.OtherModuleExists(vendorPublicLib) {
1891 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1892 } else {
1893 // This can happen if vendor_public_library module is defined in a
1894 // namespace that isn't visible to the current module. In that case,
1895 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001896 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001897 }
Dan Albert914449f2016-06-17 16:45:24 -07001898 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001899 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001900 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001901 }
1902 }
Dan Albert914449f2016-06-17 16:45:24 -07001903 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001904 }
1905
Inseob Kimeec88e12020-01-22 11:11:29 +09001906 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1907 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1908 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1909 if ctx.useVndk() {
1910 for idx, lib := range deps.RuntimeLibs {
1911 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1912 }
1913 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001914 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001915
Jiyong Park7e636d02019-01-28 16:16:54 +09001916 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001917 if c.linker != nil {
1918 if library, ok := c.linker.(*libraryDecorator); ok {
1919 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001920 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001921 }
1922 }
1923 }
1924
Inseob Kimeec88e12020-01-22 11:11:29 +09001925 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1926 // only modules with BOARD_VNDK_VERSION uses snapshot.
1927 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1928 return lib
1929 }
1930
1931 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1932 return snapshot
1933 }
1934
1935 return lib
1936 }
1937
1938 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001939 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001940 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001941 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001942 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001943 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001944
1945 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1946
Jiyong Park7e636d02019-01-28 16:16:54 +09001947 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001948 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001949 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001950 } else {
1951 actx.AddVariationDependencies(nil, depTag, lib)
1952 }
1953 }
1954
1955 if buildStubs {
1956 // Stubs lib does not have dependency to other static/shared libraries.
1957 // Don't proceed.
1958 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001959 }
Colin Cross5950f382016-12-13 12:50:57 -08001960
Inseob Kimc0907f12019-02-08 21:00:45 +09001961 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001962 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001963
Jiyong Park5d1598f2019-02-25 22:14:17 +09001964 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001965 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001966 if impl, ok := syspropImplLibraries[lib]; ok {
1967 lib = impl
1968 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001969
1970 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1971
Jiyong Park5d1598f2019-02-25 22:14:17 +09001972 actx.AddVariationDependencies([]blueprint.Variation{
1973 {Mutator: "link", Variation: "static"},
1974 }, depTag, lib)
1975 }
1976
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001977 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001978 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001979 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001980 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001981 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001982
1983 if impl, ok := syspropImplLibraries[lib]; ok {
1984 lib = impl
1985 }
1986
Inseob Kimeec88e12020-01-22 11:11:29 +09001987 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1988
Dan Willemsen59339a22018-07-22 21:18:45 -07001989 actx.AddVariationDependencies([]blueprint.Variation{
1990 {Mutator: "link", Variation: "static"},
1991 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001992 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001993
Jooyung Han75568392020-03-20 04:29:24 +09001994 // staticUnwinderDep is treated as staticDep for Q apexes
1995 // so that native libraries/binaries are linked with static unwinder
1996 // because Q libc doesn't have unwinder APIs
1997 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07001998 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001999 actx.AddVariationDependencies([]blueprint.Variation{
2000 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002001 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002002 }
2003
Inseob Kimeec88e12020-01-22 11:11:29 +09002004 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002005 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09002006 actx.AddVariationDependencies([]blueprint.Variation{
2007 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002008 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09002009 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002010
Colin Cross6e511a92020-07-27 21:26:48 -07002011 addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002012 var variations []blueprint.Variation
2013 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09002014 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002015 // Version is explicitly specified. i.e. libFoo#30
2016 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Colin Cross6e511a92020-07-27 21:26:48 -07002017 depTag.explicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09002018 }
Colin Crossd1f898e2020-08-18 18:35:15 -07002019 deps := actx.AddVariationDependencies(variations, depTag, name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002020
Jooyung Han03b51852020-02-26 22:45:42 +09002021 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002022 // The stubs library will be used when the depending module is built for APEX and
2023 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09002024 if version == "" && VersionVariantAvailable(c) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002025 if dep, ok := deps[0].(*Module); ok {
2026 for _, ver := range dep.AllStubsVersions() {
2027 // Note that depTag.ExplicitlyVersioned is false in this case.
2028 ctx.AddVariationDependencies([]blueprint.Variation{
2029 {Mutator: "link", Variation: "shared"},
2030 {Mutator: "version", Variation: ver},
2031 }, depTag, name)
2032 }
Jooyung Han03b51852020-02-26 22:45:42 +09002033 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002034 }
2035 }
2036
Jiyong Park7ed9de32018-10-15 22:25:07 +09002037 // shared lib names without the #version suffix
2038 var sharedLibNames []string
2039
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002040 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002041 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002042 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002043 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002044 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002045
2046 if impl, ok := syspropImplLibraries[lib]; ok {
2047 lib = impl
2048 }
2049
Jiyong Park73c54ee2019-10-22 20:31:18 +09002050 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002051 sharedLibNames = append(sharedLibNames, name)
2052
Jiyong Park25fc6a92018-11-18 18:02:45 +09002053 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002054 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002055
Jiyong Park7ed9de32018-10-15 22:25:07 +09002056 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002057 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002058 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2059 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2060 // linking against both the stubs lib and the non-stubs lib at the same time.
2061 continue
2062 }
Colin Cross6e511a92020-07-27 21:26:48 -07002063 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
2064 addSharedLibDependencies(depTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09002065 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002066
Dan Willemsen59339a22018-07-22 21:18:45 -07002067 actx.AddVariationDependencies([]blueprint.Variation{
2068 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002069 }, dataLibDepTag, deps.DataLibs...)
2070
2071 actx.AddVariationDependencies([]blueprint.Variation{
2072 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002073 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002074
Colin Cross68861832016-07-08 10:41:41 -07002075 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002076
2077 for _, gen := range deps.GeneratedHeaders {
2078 depTag := genHeaderDepTag
2079 if inList(gen, deps.ReexportGeneratedHeaders) {
2080 depTag = genHeaderExportDepTag
2081 }
2082 actx.AddDependency(c, depTag, gen)
2083 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002084
Colin Cross42d48b72018-08-29 14:10:52 -07002085 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002086
Inseob Kim1042d292020-06-01 23:23:05 +09002087 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2088
Dan Albert92fe7402020-07-15 13:33:30 -07002089 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07002090 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002091 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2092 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002093 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002094 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002095 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2096 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002097 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002098 if deps.LinkerFlagsFile != "" {
2099 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2100 }
2101 if deps.DynamicLinker != "" {
2102 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002103 }
Dan Albert914449f2016-06-17 16:45:24 -07002104
2105 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002106
2107 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002108 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002109 {Mutator: "ndk_api", Variation: version},
2110 {Mutator: "link", Variation: "shared"},
2111 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002112
2113 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002114 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002115 {Mutator: "ndk_api", Variation: version},
2116 {Mutator: "link", Variation: "shared"},
2117 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002118
2119 if vndkdep := c.vndkdep; vndkdep != nil {
2120 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002121 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002122 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002123 {Mutator: "link", Variation: "shared"},
2124 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002125 }
2126 }
Colin Cross6362e272015-10-29 15:25:03 -07002127}
Colin Cross21b9a242015-03-24 14:15:58 -07002128
Colin Crosse40b4ea2018-10-02 22:25:58 -07002129func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002130 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2131 c.beginMutator(ctx)
2132 }
2133}
2134
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002135// Whether a module can link to another module, taking into
2136// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002137func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2138 tag blueprint.DependencyTag) {
2139
2140 switch t := tag.(type) {
2141 case dependencyTag:
2142 if t != vndkExtDepTag {
2143 return
2144 }
2145 case libraryDependencyTag:
2146 default:
2147 return
2148 }
2149
Ivan Lozano52767be2019-10-18 14:49:46 -07002150 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002151 // Host code is not restricted
2152 return
2153 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002154
2155 // VNDK is cc.Module supported only for now.
2156 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002157 // Though vendor code is limited by the vendor mutator,
2158 // each vendor-available module needs to check
2159 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002160 if ccTo, ok := to.(*Module); ok {
2161 if ccFrom.vndkdep != nil {
2162 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2163 }
2164 } else {
2165 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002166 }
2167 return
2168 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002169 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002170 // Platform code can link to anything
2171 return
2172 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002173 if from.InRamdisk() {
2174 // Ramdisk code is not NDK
2175 return
2176 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002177 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002178 // Recovery code is not NDK
2179 return
2180 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002181 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002182 // These are always allowed
2183 return
2184 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002185 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002186 // These are allowed, but they don't set sdk_version
2187 return
2188 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002189 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002190 // These aren't real libraries, but are the stub shared libraries that are included in
2191 // the NDK.
2192 return
2193 }
Logan Chien834b9a62019-01-14 15:39:03 +08002194
Ivan Lozano52767be2019-10-18 14:49:46 -07002195 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002196 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2197 // to link to libc++ (non-NDK and without sdk_version).
2198 return
2199 }
2200
Ivan Lozano52767be2019-10-18 14:49:46 -07002201 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002202 // NDK code linking to platform code is never okay.
2203 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002204 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002205 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002206 }
2207
2208 // At this point we know we have two NDK libraries, but we need to
2209 // check that we're not linking against anything built against a higher
2210 // API level, as it is only valid to link against older or equivalent
2211 // APIs.
2212
Inseob Kim01a28722018-04-11 09:48:45 +09002213 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002214 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002215 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002216 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002217 // Current can't be linked against by anything else.
2218 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002219 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002220 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002221 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002222 if err != nil {
2223 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002224 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002225 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002226 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002227 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002228 if err != nil {
2229 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002230 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002231 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002232 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002233
Inseob Kim01a28722018-04-11 09:48:45 +09002234 if toApi > fromApi {
2235 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002236 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002237 }
2238 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002239 }
Dan Albert202fe492017-12-15 13:56:59 -08002240
2241 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002242 fromStl := from.SelectedStl()
2243 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002244 if fromStl == "" || toStl == "" {
2245 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002246 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002247 // We can be permissive with the system "STL" since it is only the C++
2248 // ABI layer, but in the future we should make sure that everyone is
2249 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002250 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002251 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002252 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2253 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002254 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002255}
2256
Jiyong Park5fb8c102018-04-09 12:03:06 +09002257// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002258// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2259// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002260// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002261func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2262 check := func(child, parent android.Module) bool {
2263 to, ok := child.(*Module)
2264 if !ok {
2265 // follow thru cc.Defaults, etc.
2266 return true
2267 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002268
Jooyung Hana70f0672019-01-18 15:20:43 +09002269 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2270 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002271 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002272
2273 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002274 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002275 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002276 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002277
Jooyung Han0302a842019-10-30 18:43:49 +09002278 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002279 return false
2280 }
2281
2282 var stringPath []string
2283 for _, m := range ctx.GetWalkPath() {
2284 stringPath = append(stringPath, m.Name())
2285 }
2286 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2287 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2288 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2289 return false
2290 }
2291 if module, ok := ctx.Module().(*Module); ok {
2292 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002293 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002294 ctx.WalkDeps(check)
2295 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002296 }
2297 }
2298}
2299
Colin Crossc99deeb2016-04-11 15:06:20 -07002300// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002301func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002302 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002303
Ivan Lozano183a3212019-10-18 14:18:45 -07002304 directStaticDeps := []LinkableInterface{}
2305 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002306
Inseob Kim69378442019-06-03 19:10:47 +09002307 reexportExporter := func(exporter exportedFlagsProducer) {
2308 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2309 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2310 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2311 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002312 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002313 }
2314
Jooyung Hande34d232020-07-23 13:04:15 +09002315 // For the dependency from platform to apex, use the latest stubs
2316 c.apexSdkVersion = android.FutureApiLevel
2317 if !c.IsForPlatform() {
2318 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2319 }
2320
2321 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2322 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2323 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2324 // (b/144430859)
2325 c.apexSdkVersion = android.FutureApiLevel
2326 }
2327
Colin Crossd11fcda2017-10-23 17:59:01 -07002328 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002329 depName := ctx.OtherModuleName(dep)
2330 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002331
Ivan Lozano52767be2019-10-18 14:49:46 -07002332 ccDep, ok := dep.(LinkableInterface)
2333 if !ok {
2334
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002335 // handling for a few module types that aren't cc Module but that are also supported
2336 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002337 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002338 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002339 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2340 genRule.GeneratedSourceFiles()...)
2341 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002342 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002343 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002344 // Support exported headers from a generated_sources dependency
2345 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002346 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002347 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002348 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002349 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002350 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002351 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002352 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002353 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002354 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2355 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002356 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002357 // 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 +09002358 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002359
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002360 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002361 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002362 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002363 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002364 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002365 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002366 files := genRule.GeneratedSourceFiles()
2367 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002368 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002369 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002370 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 -07002371 }
2372 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002373 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002374 }
Colin Crossca860ac2016-01-04 14:34:37 -08002375 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002376 return
2377 }
2378
Colin Crossfe17f6f2019-03-28 19:30:56 -07002379 if depTag == android.ProtoPluginDepTag {
2380 return
2381 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002382 if depTag == llndkImplDep {
2383 return
2384 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002385
Colin Crossd11fcda2017-10-23 17:59:01 -07002386 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002387 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2388 return
2389 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002390 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002391 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2392 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002393 return
2394 }
2395
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002396 // re-exporting flags
2397 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002398 // reusing objects only make sense for cc.Modules.
2399 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002400 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002401 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002402 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002403 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002404 return
2405 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002406 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002407
Jiyong Parke4bb9862019-02-01 00:31:10 +09002408 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002409 // staticVariants are a cc.Module specific concept.
2410 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002411 c.staticVariant = ccDep
2412 return
2413 }
2414 }
2415
Colin Cross6e511a92020-07-27 21:26:48 -07002416 checkLinkType(ctx, c, ccDep, depTag)
2417
2418 linkFile := ccDep.OutputFile()
2419
2420 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2421 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2422 if libDepTag.staticUnwinder && c.apexSdkVersion > android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002423 return
2424 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002425
Colin Cross6e511a92020-07-27 21:26:48 -07002426 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002427 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002428 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Colin Crossaede88c2020-08-11 12:17:01 -07002429 depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002430 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002431
2432 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002433 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002434 // Always respect dependency to the versioned stubs (i.e. libX#10)
2435 useThisDep = true
2436 } else if !depHasStubs {
2437 // Use non-stub variant if that is the only choice
2438 // (i.e. depending on a lib without stubs.version property)
2439 useThisDep = true
2440 } else if c.IsForPlatform() {
2441 // If not building for APEX, use stubs only when it is from
2442 // an APEX (and not from platform)
2443 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002444 if c.bootstrap() {
2445 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002446 // always link to non-stub variant
2447 useThisDep = !depIsStubs
2448 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002449 for _, testFor := range c.TestFor() {
2450 // Another exception: if this module is bundled with an APEX, then
2451 // it is linked with the non-stub variant of a module in the APEX
2452 // as if this is part of the APEX.
2453 if android.DirectlyInApex(testFor, depName) {
2454 useThisDep = !depIsStubs
2455 break
2456 }
2457 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002458 } else {
Colin Crossaede88c2020-08-11 12:17:01 -07002459 // If building for APEX, use stubs when the parent is in any APEX that
2460 // the child is not in.
2461 useThisDep = (depInSameApexes != depIsStubs)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002462 }
2463
Jooyung Han03b51852020-02-26 22:45:42 +09002464 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002465 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Jooyung Han75568392020-03-20 04:29:24 +09002466 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002467 if err != nil {
2468 ctx.OtherModuleErrorf(dep, err.Error())
2469 return
2470 }
2471 if versionToUse != ccDep.StubsVersion() {
2472 useThisDep = false
2473 }
2474 }
2475
Jiyong Park25fc6a92018-11-18 18:02:45 +09002476 if !useThisDep {
2477 return // stop processing this dep
2478 }
2479 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002480 if c.UseVndk() {
2481 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2482 // by default, use current version of LLNDK
2483 versionToUse := ""
Colin Crossd1f898e2020-08-18 18:35:15 -07002484 versions := m.AllStubsVersions()
Colin Crosse07f2312020-08-13 11:24:56 -07002485 if c.ApexVariationName() != "" && len(versions) > 0 {
Jooyung Han61b66e92020-03-21 14:21:46 +00002486 // if this is for use_vendor apex && dep has stubsVersions
2487 // apply the same rule of apex sdk enforcement to choose right version
2488 var err error
Jooyung Han75568392020-03-20 04:29:24 +09002489 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002490 if err != nil {
2491 ctx.OtherModuleErrorf(dep, err.Error())
2492 return
2493 }
2494 }
2495 if versionToUse != ccDep.StubsVersion() {
2496 return
2497 }
2498 }
2499 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002500
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002501 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2502
Ivan Lozano52767be2019-10-18 14:49:46 -07002503 // Exporting flags only makes sense for cc.Modules
2504 if _, ok := ccDep.(*Module); ok {
2505 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002506 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002507 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002508 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002509
Colin Cross6e511a92020-07-27 21:26:48 -07002510 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002511 reexportExporter(i)
2512 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2513 // Re-exported shared library headers must be included as well since they can help us with type information
2514 // about template instantiations (instantiated from their headers).
2515 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2516 // scripts.
2517 c.sabi.Properties.ReexportedIncludes = append(
2518 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2519 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002520 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002521 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002522
Colin Cross6e511a92020-07-27 21:26:48 -07002523 var ptr *android.Paths
2524 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002525
Colin Cross6e511a92020-07-27 21:26:48 -07002526 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002527
Colin Cross6e511a92020-07-27 21:26:48 -07002528 switch {
2529 case libDepTag.header():
2530 // nothing
2531 case libDepTag.shared():
2532 ptr = &depPaths.SharedLibs
2533 switch libDepTag.Order {
2534 case earlyLibraryDependency:
2535 ptr = &depPaths.EarlySharedLibs
2536 depPtr = &depPaths.EarlySharedLibsDeps
2537 case normalLibraryDependency:
2538 ptr = &depPaths.SharedLibs
2539 depPtr = &depPaths.SharedLibsDeps
2540 directSharedDeps = append(directSharedDeps, ccDep)
2541 case lateLibraryDependency:
2542 ptr = &depPaths.LateSharedLibs
2543 depPtr = &depPaths.LateSharedLibsDeps
2544 default:
2545 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002546 }
Colin Cross6e511a92020-07-27 21:26:48 -07002547 depFile = ccDep.Toc()
2548 case libDepTag.static():
2549 if libDepTag.wholeStatic {
2550 ptr = &depPaths.WholeStaticLibs
2551 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2552 ctx.ModuleErrorf("module %q not a static library", depName)
2553 return
Inseob Kim752edec2020-03-14 01:30:34 +09002554 }
2555
Colin Cross6e511a92020-07-27 21:26:48 -07002556 // Because the static library objects are included, this only makes sense
2557 // in the context of proper cc.Modules.
2558 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2559 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2560 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2561 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2562 for i := range missingDeps {
2563 missingDeps[i] += postfix
2564 }
2565 ctx.AddMissingDependencies(missingDeps)
2566 }
2567 if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
2568 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
2569 } else {
2570 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2571 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002572 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002573 ctx.ModuleErrorf(
2574 "non-cc.Modules cannot be included as whole static libraries.", depName)
2575 return
2576 }
2577
2578 } else {
2579 switch libDepTag.Order {
2580 case earlyLibraryDependency:
2581 panic(fmt.Errorf("early static libs not suppported"))
2582 case normalLibraryDependency:
2583 // static dependencies will be handled separately so they can be ordered
2584 // using transitive dependencies.
2585 ptr = nil
2586 directStaticDeps = append(directStaticDeps, ccDep)
2587 case lateLibraryDependency:
2588 ptr = &depPaths.LateStaticLibs
2589 default:
2590 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002591 }
2592 }
2593 }
2594
Colin Cross6e511a92020-07-27 21:26:48 -07002595 if libDepTag.static() && !libDepTag.wholeStatic {
2596 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2597 ctx.ModuleErrorf("module %q not a static library", depName)
2598 return
2599 }
Logan Chien43d34c32017-12-20 01:17:32 +08002600
Colin Cross6e511a92020-07-27 21:26:48 -07002601 // When combining coverage files for shared libraries and executables, coverage files
2602 // in static libraries act as if they were whole static libraries. The same goes for
2603 // source based Abi dump files.
2604 if c, ok := ccDep.(*Module); ok {
2605 staticLib := c.linker.(libraryInterface)
2606 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2607 staticLib.objs().coverageFiles...)
2608 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2609 staticLib.objs().sAbiDumpFiles...)
2610 } else if c, ok := ccDep.(LinkableInterface); ok {
2611 // Handle non-CC modules here
2612 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2613 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002614 }
2615 }
2616
Colin Cross6e511a92020-07-27 21:26:48 -07002617 if ptr != nil {
2618 if !linkFile.Valid() {
2619 if !ctx.Config().AllowMissingDependencies() {
2620 ctx.ModuleErrorf("module %q missing output file", depName)
2621 } else {
2622 ctx.AddMissingDependencies([]string{depName})
2623 }
2624 return
2625 }
2626 *ptr = append(*ptr, linkFile.Path())
2627 }
2628
2629 if depPtr != nil {
2630 dep := depFile
2631 if !dep.Valid() {
2632 dep = linkFile
2633 }
2634 *depPtr = append(*depPtr, dep.Path())
2635 }
2636
2637 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2638 switch {
2639 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002640 c.Properties.AndroidMkHeaderLibs = append(
2641 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002642 case libDepTag.shared():
2643 if ccDep.CcLibrary() {
2644 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2645 // Add the dependency to the APEX(es) providing the library so that
2646 // m <module> can trigger building the APEXes as well.
2647 for _, an := range android.GetApexesForModule(depName) {
2648 c.Properties.ApexesProvidingSharedLibs = append(
2649 c.Properties.ApexesProvidingSharedLibs, an)
2650 }
2651 }
2652 }
2653
2654 // Note: the order of libs in this list is not important because
2655 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002656 c.Properties.AndroidMkSharedLibs = append(
2657 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002658 // Record baseLibName for snapshots.
2659 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2660 case libDepTag.static():
2661 if libDepTag.wholeStatic {
2662 c.Properties.AndroidMkWholeStaticLibs = append(
2663 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2664 } else {
2665 c.Properties.AndroidMkStaticLibs = append(
2666 c.Properties.AndroidMkStaticLibs, makeLibName)
2667 }
2668 }
2669 } else {
2670 switch depTag {
2671 case runtimeDepTag:
2672 c.Properties.AndroidMkRuntimeLibs = append(
2673 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2674 // Record baseLibName for snapshots.
2675 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2676 case objDepTag:
2677 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2678 case CrtBeginDepTag:
2679 depPaths.CrtBegin = linkFile
2680 case CrtEndDepTag:
2681 depPaths.CrtEnd = linkFile
2682 case dynamicLinkerDepTag:
2683 depPaths.DynamicLinker = linkFile
2684 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002685 }
Colin Crossca860ac2016-01-04 14:34:37 -08002686 })
2687
Jeff Gaston294356f2017-09-27 17:05:30 -07002688 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002689 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002690
Colin Crossdd84e052017-05-17 13:44:16 -07002691 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002692 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002693 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2694 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002695 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002696 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2697 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002698 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002699 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002700 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002701
2702 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002703 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002704 }
Colin Crossdd84e052017-05-17 13:44:16 -07002705
Colin Crossca860ac2016-01-04 14:34:37 -08002706 return depPaths
2707}
2708
Colin Cross6e511a92020-07-27 21:26:48 -07002709// baseLibName trims known prefixes and suffixes
2710func baseLibName(depName string) string {
2711 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2712 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2713 libName = strings.TrimPrefix(libName, "prebuilt_")
2714 return libName
2715}
2716
2717func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2718 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2719 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2720
2721 libName := baseLibName(depName)
2722 isLLndk := isLlndkLibrary(libName, ctx.Config())
2723 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2724 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2725
2726 if c, ok := ccDep.(*Module); ok {
2727 // Use base module name for snapshots when exporting to Makefile.
2728 if c.isSnapshotPrebuilt() {
2729 baseName := c.BaseModuleName()
2730
2731 if c.IsVndk() {
2732 return baseName + ".vendor"
2733 }
2734
2735 if vendorSuffixModules[baseName] {
2736 return baseName + ".vendor"
2737 } else {
2738 return baseName
2739 }
2740 }
2741 }
2742
2743 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2744 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2745 // core module instead.
2746 return libName
2747 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2748 // The vendor module in Make will have been renamed to not conflict with the core
2749 // module, so update the dependency name here accordingly.
2750 return libName + c.getNameSuffixWithVndkVersion(ctx)
2751 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2752 return libName + vendorPublicLibrarySuffix
2753 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2754 return libName + ramdiskSuffix
2755 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2756 return libName + recoverySuffix
2757 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2758 return libName + nativeBridgeSuffix
2759 } else {
2760 return libName
2761 }
2762}
2763
Colin Crossca860ac2016-01-04 14:34:37 -08002764func (c *Module) InstallInData() bool {
2765 if c.installer == nil {
2766 return false
2767 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002768 return c.installer.inData()
2769}
2770
2771func (c *Module) InstallInSanitizerDir() bool {
2772 if c.installer == nil {
2773 return false
2774 }
2775 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002776 return true
2777 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002778 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002779}
2780
Yifan Hong1b3348d2020-01-21 15:53:22 -08002781func (c *Module) InstallInRamdisk() bool {
2782 return c.InRamdisk()
2783}
2784
Jiyong Parkf9332f12018-02-01 00:54:12 +09002785func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002786 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002787}
2788
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002789func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002790 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002791 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002792 return
2793 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002794 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002795}
2796
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002797func (c *Module) HostToolPath() android.OptionalPath {
2798 if c.installer == nil {
2799 return android.OptionalPath{}
2800 }
2801 return c.installer.hostToolPath()
2802}
2803
Nan Zhangd4e641b2017-07-12 12:55:28 -07002804func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2805 return c.outputFile
2806}
2807
Colin Cross41955e82019-05-29 14:40:35 -07002808func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2809 switch tag {
2810 case "":
2811 if c.outputFile.Valid() {
2812 return android.Paths{c.outputFile.Path()}, nil
2813 }
2814 return android.Paths{}, nil
2815 default:
2816 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002817 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002818}
2819
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002820func (c *Module) static() bool {
2821 if static, ok := c.linker.(interface {
2822 static() bool
2823 }); ok {
2824 return static.static()
2825 }
2826 return false
2827}
2828
Jiyong Park379de2f2018-12-19 02:47:14 +09002829func (c *Module) staticBinary() bool {
2830 if static, ok := c.linker.(interface {
2831 staticBinary() bool
2832 }); ok {
2833 return static.staticBinary()
2834 }
2835 return false
2836}
2837
Jiyong Park1d1119f2019-07-29 21:27:18 +09002838func (c *Module) header() bool {
2839 if h, ok := c.linker.(interface {
2840 header() bool
2841 }); ok {
2842 return h.header()
2843 }
2844 return false
2845}
2846
Inseob Kim7f283f42020-06-01 21:53:49 +09002847func (c *Module) binary() bool {
2848 if b, ok := c.linker.(interface {
2849 binary() bool
2850 }); ok {
2851 return b.binary()
2852 }
2853 return false
2854}
2855
Inseob Kim1042d292020-06-01 23:23:05 +09002856func (c *Module) object() bool {
2857 if o, ok := c.linker.(interface {
2858 object() bool
2859 }); ok {
2860 return o.object()
2861 }
2862 return false
2863}
2864
Jooyung Han38002912019-05-16 04:01:54 +09002865func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002866 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002867 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2868 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002869 return "native:vndk"
2870 }
Jooyung Han38002912019-05-16 04:01:54 +09002871 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002872 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002873 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002874 if Bool(c.VendorProperties.Vendor_available) {
2875 return "native:vndk"
2876 }
2877 return "native:vndk_private"
2878 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002879 if c.inProduct() {
2880 return "native:product"
2881 }
Jooyung Han38002912019-05-16 04:01:54 +09002882 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002883 } else if c.InRamdisk() {
2884 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002885 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002886 return "native:recovery"
2887 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2888 return "native:ndk:none:none"
2889 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2890 //family, link := getNdkStlFamilyAndLinkType(c)
2891 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002892 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002893 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002894 } else {
2895 return "native:platform"
2896 }
2897}
2898
Jiyong Park9d452992018-10-03 00:38:19 +09002899// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002900// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002901func (c *Module) IsInstallableToApex() bool {
2902 if shared, ok := c.linker.(interface {
2903 shared() bool
2904 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002905 // Stub libs and prebuilt libs in a versioned SDK are not
2906 // installable to APEX even though they are shared libs.
2907 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002908 } else if _, ok := c.linker.(testPerSrc); ok {
2909 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002910 }
2911 return false
2912}
2913
Jiyong Parka90ca002019-10-07 15:47:24 +09002914func (c *Module) AvailableFor(what string) bool {
2915 if linker, ok := c.linker.(interface {
2916 availableFor(string) bool
2917 }); ok {
2918 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2919 } else {
2920 return c.ApexModuleBase.AvailableFor(what)
2921 }
2922}
2923
Jiyong Park62304bb2020-04-13 16:19:48 +09002924func (c *Module) TestFor() []string {
2925 if test, ok := c.linker.(interface {
2926 testFor() []string
2927 }); ok {
2928 return test.testFor()
2929 } else {
2930 return c.ApexModuleBase.TestFor()
2931 }
2932}
2933
Colin Crossaede88c2020-08-11 12:17:01 -07002934func (c *Module) UniqueApexVariations() bool {
2935 if u, ok := c.compiler.(interface {
2936 uniqueApexVariations() bool
2937 }); ok {
2938 return u.uniqueApexVariations()
2939 } else {
2940 return false
2941 }
2942}
2943
Paul Duffin0cb37b92020-03-04 14:52:46 +00002944// Return true if the module is ever installable.
2945func (c *Module) EverInstallable() bool {
2946 return c.installer != nil &&
2947 // Check to see whether the module is actually ever installable.
2948 c.installer.everInstallable()
2949}
2950
Inseob Kim1f086e22019-05-09 13:29:15 +09002951func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002952 ret := c.EverInstallable() &&
2953 // Check to see whether the module has been configured to not be installed.
2954 proptools.BoolDefault(c.Properties.Installable, true) &&
2955 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002956
2957 // The platform variant doesn't need further condition. Apex variants however might not
2958 // be installable because it will likely to be included in the APEX and won't appear
2959 // in the system partition.
2960 if c.IsForPlatform() {
2961 return ret
2962 }
2963
2964 // Special case for modules that are configured to be installed to /data, which includes
2965 // test modules. For these modules, both APEX and non-APEX variants are considered as
2966 // installable. This is because even the APEX variants won't be included in the APEX, but
2967 // will anyway be installed to /data/*.
2968 // See b/146995717
2969 if c.InstallInData() {
2970 return ret
2971 }
2972
2973 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002974}
2975
Logan Chien41eabe62019-04-10 13:33:58 +08002976func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2977 if c.linker != nil {
2978 if library, ok := c.linker.(*libraryDecorator); ok {
2979 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2980 }
2981 }
2982}
2983
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002984func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002985 depTag := ctx.OtherModuleDependencyTag(dep)
2986 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2987
2988 if cc, ok := dep.(*Module); ok {
2989 if cc.HasStubsVariants() {
2990 if isLibDepTag && libDepTag.shared() {
2991 // dynamic dep to a stubs lib crosses APEX boundary
2992 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002993 }
Colin Cross6e511a92020-07-27 21:26:48 -07002994 if IsRuntimeDepTag(depTag) {
2995 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002996 return false
2997 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002998 }
Colin Crossaac32222020-07-29 12:51:56 -07002999 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07003000 // shared_lib dependency from a static lib is considered as crossing
3001 // the APEX boundary because the dependency doesn't actually is
3002 // linked; the dependency is used only during the compilation phase.
3003 return false
3004 }
3005 }
3006 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09003007 // We don't track beyond LLNDK
3008 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003009 }
3010 return true
3011}
3012
Jooyung Han749dc692020-04-15 11:03:39 +09003013// b/154667674: refactor this to handle "current" in a consistent way
3014func decodeSdkVersionString(ctx android.BaseModuleContext, versionString string) (int, error) {
3015 if versionString == "" {
3016 return 0, fmt.Errorf("not specified")
3017 }
3018 if versionString == "current" {
3019 if ctx.Config().PlatformSdkCodename() == "REL" {
3020 return ctx.Config().PlatformSdkVersionInt(), nil
3021 }
3022 return android.FutureApiLevel, nil
3023 }
3024 return android.ApiStrToNum(ctx, versionString)
3025}
3026
3027func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error {
3028 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3029 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3030 return nil
3031 }
3032 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3033 if c.ToolchainLibrary() {
3034 return nil
3035 }
3036 // We don't check for prebuilt modules
3037 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3038 return nil
3039 }
3040 minSdkVersion := c.MinSdkVersion()
3041 if minSdkVersion == "apex_inherit" {
3042 return nil
3043 }
3044 if minSdkVersion == "" {
3045 // JNI libs within APK-in-APEX fall into here
3046 // Those are okay to set sdk_version instead
3047 // We don't have to check if this is a SDK variant because
3048 // non-SDK variant resets sdk_version, which works too.
3049 minSdkVersion = c.SdkVersion()
3050 }
3051 ver, err := decodeSdkVersionString(ctx, minSdkVersion)
3052 if err != nil {
3053 return err
3054 }
3055 if ver > sdkVersion {
3056 return fmt.Errorf("newer SDK(%v)", ver)
3057 }
3058 return nil
3059}
3060
Colin Cross2ba19d92015-05-07 15:44:20 -07003061//
Colin Crosscfad1192015-11-02 16:43:11 -08003062// Defaults
3063//
Colin Crossca860ac2016-01-04 14:34:37 -08003064type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003065 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003066 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003067 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003068}
3069
Patrice Arrudac249c712019-03-19 17:00:29 -07003070// cc_defaults provides a set of properties that can be inherited by other cc
3071// modules. A module can use the properties from a cc_defaults using
3072// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3073// merged (when possible) by prepending the default module's values to the
3074// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003075func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003076 return DefaultsFactory()
3077}
3078
Colin Cross36242852017-06-23 15:06:31 -07003079func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003080 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003081
Colin Cross36242852017-06-23 15:06:31 -07003082 module.AddProperties(props...)
3083 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003084 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003085 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003086 &BaseCompilerProperties{},
3087 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003088 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003089 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003090 &StaticProperties{},
3091 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003092 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003093 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003094 &TestProperties{},
3095 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003096 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003097 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003098 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003099 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003100 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003101 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003102 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003103 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003104 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003105 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003106 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003107 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003108 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003109 )
Colin Crosscfad1192015-11-02 16:43:11 -08003110
Jooyung Hancc372c52019-09-25 15:18:44 +09003111 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003112
3113 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003114}
3115
Jiyong Park6a43f042017-10-12 23:05:00 +09003116func squashVendorSrcs(m *Module) {
3117 if lib, ok := m.compiler.(*libraryDecorator); ok {
3118 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3119 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3120
3121 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3122 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003123
3124 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3125 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003126 }
3127}
3128
Jiyong Parkf9332f12018-02-01 00:54:12 +09003129func squashRecoverySrcs(m *Module) {
3130 if lib, ok := m.compiler.(*libraryDecorator); ok {
3131 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3132 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3133
3134 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3135 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003136
3137 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3138 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003139 }
3140}
3141
Jiyong Park2286afd2020-06-16 21:58:53 +09003142func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003143 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003144}
3145
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003146func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003147 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003148 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3149 }
Colin Cross6510f912017-11-29 00:27:14 -08003150 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003151}
3152
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003153func kytheExtractAllFactory() android.Singleton {
3154 return &kytheExtractAllSingleton{}
3155}
3156
3157type kytheExtractAllSingleton struct {
3158}
3159
3160func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3161 var xrefTargets android.Paths
3162 ctx.VisitAllModules(func(module android.Module) {
3163 if ccModule, ok := module.(xref); ok {
3164 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3165 }
3166 })
3167 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3168 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003169 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003170 }
3171}
3172
Colin Cross06a931b2015-10-28 17:23:31 -07003173var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003174var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003175var BoolPtr = proptools.BoolPtr
3176var String = proptools.String
3177var StringPtr = proptools.StringPtr