blob: b5777f426675c105b420a11f14002100e3b35592 [file] [log] [blame]
Ivan Lozano183a3212019-10-18 14:18:45 -07001package cc
2
3import (
Ivan Lozano183a3212019-10-18 14:18:45 -07004 "android/soong/android"
Liz Kammerb6a55bf2021-04-12 15:42:51 -04005 "android/soong/bazel/cquery"
Colin Cross6e511a92020-07-27 21:26:48 -07006
7 "github.com/google/blueprint"
Ivan Lozano183a3212019-10-18 14:18:45 -07008)
9
Ivan Lozano3968d8f2020-12-14 11:27:52 -050010// PlatformSanitizeable is an interface for sanitizing platform modules.
11type PlatformSanitizeable interface {
12 LinkableInterface
13
14 // SanitizePropDefined returns whether the Sanitizer properties struct for this module is defined.
15 SanitizePropDefined() bool
16
17 // IsDependencyRoot returns whether a module is of a type which cannot be a linkage dependency
18 // of another module. For example, cc_binary and rust_binary represent dependency roots as other
19 // modules cannot have linkage dependencies against these types.
20 IsDependencyRoot() bool
21
22 // IsSanitizerEnabled returns whether a sanitizer is enabled.
23 IsSanitizerEnabled(t SanitizerType) bool
24
25 // IsSanitizerExplicitlyDisabled returns whether a sanitizer has been explicitly disabled (set to false) rather
26 // than left undefined.
27 IsSanitizerExplicitlyDisabled(t SanitizerType) bool
28
29 // SanitizeDep returns the value of the SanitizeDep flag, which is set if a module is a dependency of a
30 // sanitized module.
31 SanitizeDep() bool
32
33 // SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
34 SetSanitizer(t SanitizerType, b bool)
35
36 // SetSanitizerDep returns true if the module is statically linked.
37 SetSanitizeDep(b bool)
38
39 // StaticallyLinked returns true if the module is statically linked.
40 StaticallyLinked() bool
41
42 // SetInSanitizerDir sets the module installation to the sanitizer directory.
43 SetInSanitizerDir()
44
45 // SanitizeNever returns true if this module should never be sanitized.
46 SanitizeNever() bool
47
48 // SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
49 SanitizerSupported(t SanitizerType) bool
50
Ivan Lozanod7586b62021-04-01 09:49:36 -040051 // MinimalRuntimeDep returns true if this module needs to link the minimal UBSan runtime,
52 // either because it requires it or because a dependent module which requires it to be linked in this module.
53 MinimalRuntimeDep() bool
54
55 // UbsanRuntimeDep returns true if this module needs to link the full UBSan runtime,
56 // either because it requires it or because a dependent module which requires it to be linked in this module.
57 UbsanRuntimeDep() bool
58
59 // UbsanRuntimeNeeded returns true if the full UBSan runtime is required by this module.
60 UbsanRuntimeNeeded() bool
61
62 // MinimalRuntimeNeeded returns true if the minimal UBSan runtime is required by this module
63 MinimalRuntimeNeeded() bool
64
Ivan Lozano3968d8f2020-12-14 11:27:52 -050065 // SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
66 SanitizableDepTagChecker() SantizableDependencyTagChecker
67}
68
69// SantizableDependencyTagChecker functions check whether or not a dependency
70// tag can be sanitized. These functions should return true if the tag can be
71// sanitized, otherwise they should return false. These functions should also
72// handle all possible dependency tags in the dependency tree. For example,
73// Rust modules can depend on both Rust and CC libraries, so the Rust module
74// implementation should handle tags from both.
75type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
76
Ivan Lozanod7586b62021-04-01 09:49:36 -040077// Snapshottable defines those functions necessary for handling module snapshots.
78type Snapshottable interface {
79 // SnapshotHeaders returns a list of header paths provided by this module.
80 SnapshotHeaders() android.Paths
81
82 // ExcludeFromVendorSnapshot returns true if this module should be otherwise excluded from the vendor snapshot.
83 ExcludeFromVendorSnapshot() bool
84
85 // ExcludeFromRecoverySnapshot returns true if this module should be otherwise excluded from the recovery snapshot.
86 ExcludeFromRecoverySnapshot() bool
87
88 // SnapshotLibrary returns true if this module is a snapshot library.
89 IsSnapshotLibrary() bool
90
Justin Yun885a7de2021-06-29 20:34:53 +090091 // EffectiveLicenseFiles returns the list of License files for this module.
92 EffectiveLicenseFiles() android.Paths
93
Ivan Lozanod7586b62021-04-01 09:49:36 -040094 // SnapshotRuntimeLibs returns a list of libraries needed by this module at runtime but which aren't build dependencies.
95 SnapshotRuntimeLibs() []string
96
97 // SnapshotSharedLibs returns the list of shared library dependencies for this module.
98 SnapshotSharedLibs() []string
99
Justin Yun5e035862021-06-29 20:50:37 +0900100 // SnapshotStaticLibs returns the list of static library dependencies for this module.
101 SnapshotStaticLibs() []string
102
Ivan Lozanod7586b62021-04-01 09:49:36 -0400103 // IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
104 IsSnapshotPrebuilt() bool
105}
106
Chris Parsons3c27ca32020-11-20 12:42:07 -0500107// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
Ivan Lozano183a3212019-10-18 14:18:45 -0700108type LinkableInterface interface {
Ivan Lozanof9e21722020-12-02 09:00:51 -0500109 android.Module
Ivan Lozanod7586b62021-04-01 09:49:36 -0400110 Snapshottable
Ivan Lozanof9e21722020-12-02 09:00:51 -0500111
Ivan Lozano183a3212019-10-18 14:18:45 -0700112 Module() android.Module
113 CcLibrary() bool
114 CcLibraryInterface() bool
115
Ivan Lozanod7586b62021-04-01 09:49:36 -0400116 // BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
117 BaseModuleName() string
118
Ivan Lozano183a3212019-10-18 14:18:45 -0700119 OutputFile() android.OptionalPath
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400120 CoverageFiles() android.Paths
Ivan Lozano183a3212019-10-18 14:18:45 -0700121
Ivan Lozano2b262972019-11-21 12:30:50 -0800122 NonCcVariants() bool
123
Ivan Lozano52767be2019-10-18 14:49:46 -0700124 SelectedStl() string
Ivan Lozano183a3212019-10-18 14:18:45 -0700125
126 BuildStaticVariant() bool
127 BuildSharedVariant() bool
128 SetStatic()
129 SetShared()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500130 IsPrebuilt() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700131 Toc() android.OptionalPath
132
Jooyung Han624d35c2020-04-10 12:57:24 +0900133 Host() bool
134
Yifan Hong1b3348d2020-01-21 15:53:22 -0800135 InRamdisk() bool
136 OnlyInRamdisk() bool
137
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700138 InVendorRamdisk() bool
139 OnlyInVendorRamdisk() bool
140
Ivan Lozano52767be2019-10-18 14:49:46 -0700141 InRecovery() bool
142 OnlyInRecovery() bool
143
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500144 InVendor() bool
145
Colin Crossc511bc52020-04-07 16:50:32 +0000146 UseSdk() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400147
148 // IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
149 IsLlndk() bool
150
151 // IsLlndkPublic returns true only for LLNDK (public) libs.
152 IsLlndkPublic() bool
153
Ivan Lozanod7586b62021-04-01 09:49:36 -0400154 // HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
155 HasLlndkStubs() bool
156
Colin Cross1f3f1302021-04-26 18:37:44 -0700157 // NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
158 NeedsLlndkVariants() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400159
Colin Cross5271fea2021-04-27 13:06:04 -0700160 // NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
161 NeedsVendorPublicLibraryVariants() bool
162
Ivan Lozanod7586b62021-04-01 09:49:36 -0400163 //StubsVersion returns the stubs version for this module.
164 StubsVersion() string
165
166 // UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
167 // "product" and "vendor" variant modules return true for this function.
168 // When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
169 // "soc_specific: true" and more vendor installed modules are included here.
170 // When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
171 // "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700172 UseVndk() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400173
Jiyong Park7d55b612021-06-11 17:22:09 +0900174 // Bootstrap tests if this module is allowed to use non-APEX version of libraries.
175 Bootstrap() bool
176
Ivan Lozanod7586b62021-04-01 09:49:36 -0400177 // IsVndkSp returns true if this is a VNDK-SP module.
178 IsVndkSp() bool
179
Ivan Lozano52767be2019-10-18 14:49:46 -0700180 MustUseVendorVariant() bool
181 IsVndk() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500182 IsVndkExt() bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800183 IsVndkPrivate() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700184 HasVendorVariant() bool
Justin Yuncbca3732021-02-03 19:24:13 +0900185 HasProductVariant() bool
186 HasNonSystemVariants() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500187 InProduct() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700188
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400189 // SubName returns the modules SubName, used for image and NDK/SDK variations.
190 SubName() string
191
Ivan Lozano52767be2019-10-18 14:49:46 -0700192 SdkVersion() string
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900193 MinSdkVersion() string
Colin Crossc511bc52020-04-07 16:50:32 +0000194 AlwaysSdk() bool
Jiyong Park2286afd2020-06-16 21:58:53 +0900195 IsSdkVariant() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700196
Colin Cross1348ce32020-10-01 13:37:16 -0700197 SplitPerApiLevel() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500198
199 // SetPreventInstall sets the PreventInstall property to 'true' for this module.
200 SetPreventInstall()
201 // SetHideFromMake sets the HideFromMake property to 'true' for this module.
202 SetHideFromMake()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400203
204 // KernelHeadersDecorator returns true if this is a kernel headers decorator module.
205 // This is specific to cc and should always return false for all other packages.
206 KernelHeadersDecorator() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400207
208 // HiddenFromMake returns true if this module is hidden from Make.
209 HiddenFromMake() bool
210
211 // RelativeInstallPath returns the relative install path for this module.
212 RelativeInstallPath() string
213
214 // Binary returns true if this is a binary module.
215 Binary() bool
216
217 // Object returns true if this is an object module.
218 Object() bool
219
220 // Rlib returns true if this is an rlib module.
221 Rlib() bool
222
223 // Dylib returns true if this is an dylib module.
224 Dylib() bool
225
226 // Static returns true if this is a static library module.
227 Static() bool
228
229 // Shared returns true if this is a shared library module.
230 Shared() bool
231
232 // Header returns true if this is a library headers module.
233 Header() bool
234
Justin Yun5e035862021-06-29 20:50:37 +0900235 // StaticExecutable returns true if this is a binary module with "static_executable: true".
236 StaticExecutable() bool
237
Ivan Lozanod7586b62021-04-01 09:49:36 -0400238 // EverInstallable returns true if the module is ever installable
239 EverInstallable() bool
240
241 // PreventInstall returns true if this module is prevented from installation.
242 PreventInstall() bool
243
244 // InstallInData returns true if this module is installed in data.
245 InstallInData() bool
246
247 // Installable returns a bool pointer to the module installable property.
248 Installable() *bool
249
250 // Symlinks returns a list of symlinks that should be created for this module.
251 Symlinks() []string
252
253 // VndkVersion returns the VNDK version string for this module.
254 VndkVersion() string
Ivan Lozano183a3212019-10-18 14:18:45 -0700255}
256
Colin Cross6e511a92020-07-27 21:26:48 -0700257var (
Chris Parsons3c27ca32020-11-20 12:42:07 -0500258 // Dependency tag for crtbegin, an object file responsible for initialization.
Colin Cross6e511a92020-07-27 21:26:48 -0700259 CrtBeginDepTag = dependencyTag{name: "crtbegin"}
Chris Parsons3c27ca32020-11-20 12:42:07 -0500260 // Dependency tag for crtend, an object file responsible for program termination.
261 CrtEndDepTag = dependencyTag{name: "crtend"}
262 // Dependency tag for coverage library.
Colin Cross6e511a92020-07-27 21:26:48 -0700263 CoverageDepTag = dependencyTag{name: "coverage"}
264)
Ivan Lozano183a3212019-10-18 14:18:45 -0700265
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500266// GetImageVariantType returns the ImageVariantType string value for the given module
267// (these are defined in cc/image.go).
268func GetImageVariantType(c LinkableInterface) ImageVariantType {
269 if c.Host() {
270 return hostImageVariant
271 } else if c.InVendor() {
272 return vendorImageVariant
273 } else if c.InProduct() {
274 return productImageVariant
275 } else if c.InRamdisk() {
276 return ramdiskImageVariant
277 } else if c.InVendorRamdisk() {
278 return vendorRamdiskImageVariant
279 } else if c.InRecovery() {
280 return recoveryImageVariant
281 } else {
282 return coreImageVariant
283 }
284}
285
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400286// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
287// Returns an empty string if not a library dependency tag.
288func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
289 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
290 return libDepTag.makeSuffix
291 }
292 return ""
293}
294
Chris Parsons3c27ca32020-11-20 12:42:07 -0500295// SharedDepTag returns the dependency tag for any C++ shared libraries.
Colin Cross6e511a92020-07-27 21:26:48 -0700296func SharedDepTag() blueprint.DependencyTag {
297 return libraryDependencyTag{Kind: sharedLibraryDependency}
Ivan Lozano183a3212019-10-18 14:18:45 -0700298}
299
Chris Parsons3c27ca32020-11-20 12:42:07 -0500300// StaticDepTag returns the dependency tag for any C++ static libraries.
Ivan Lozano63bb7682021-03-23 15:53:44 -0400301func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
302 return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
303}
304
305// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
306func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
307 if tag, ok := depTag.(libraryDependencyTag); ok {
308 return tag.wholeStatic
309 }
310 return false
Colin Cross6e511a92020-07-27 21:26:48 -0700311}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700312
Chris Parsons3c27ca32020-11-20 12:42:07 -0500313// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
Zach Johnson3df4e632020-11-06 11:56:27 -0800314func HeaderDepTag() blueprint.DependencyTag {
315 return libraryDependencyTag{Kind: headerLibraryDependency}
316}
317
Chris Parsons3c27ca32020-11-20 12:42:07 -0500318// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700319type SharedLibraryInfo struct {
Liz Kammeref6dfea2021-06-08 15:37:09 -0400320 SharedLibrary android.Path
321 Target android.Target
Colin Cross0de8a1e2020-09-18 14:15:30 -0700322
Liz Kammeref6dfea2021-06-08 15:37:09 -0400323 TableOfContents android.OptionalPath
Colin Cross0de8a1e2020-09-18 14:15:30 -0700324
Liz Kammeref6dfea2021-06-08 15:37:09 -0400325 // should be obtained from static analogue
326 TransitiveStaticLibrariesForOrdering *android.DepSet
Colin Cross0de8a1e2020-09-18 14:15:30 -0700327}
328
329var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
330
Chris Parsons3c27ca32020-11-20 12:42:07 -0500331// SharedStubLibrary is a struct containing information about a stub shared library.
332// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
333// library in another APEX, it must depend on the stub version of that library.
334type SharedStubLibrary struct {
335 // The version of the stub (corresponding to the stable version of the shared library being
336 // stubbed).
Colin Cross0de8a1e2020-09-18 14:15:30 -0700337 Version string
338 SharedLibraryInfo SharedLibraryInfo
339 FlagExporterInfo FlagExporterInfo
340}
341
Chris Parsons3c27ca32020-11-20 12:42:07 -0500342// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
343// which are dependencies of a library.
344// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
345// library in another APEX, it must depend on the stub version of that library.
346type SharedLibraryStubsInfo struct {
347 SharedStubLibraries []SharedStubLibrary
Colin Cross0de8a1e2020-09-18 14:15:30 -0700348
Chris Parsons3c27ca32020-11-20 12:42:07 -0500349 IsLLNDK bool
350}
351
352var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{})
353
354// StaticLibraryInfo is a provider to propagate information about a static C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700355type StaticLibraryInfo struct {
356 StaticLibrary android.Path
357 Objects Objects
358 ReuseObjects Objects
359
360 // This isn't the actual transitive DepSet, shared library dependencies have been
361 // converted into static library analogues. It is only used to order the static
362 // library dependencies that were specified for the current module.
363 TransitiveStaticLibrariesForOrdering *android.DepSet
364}
365
366var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
367
Colin Cross649d8172020-12-10 12:30:21 -0800368// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
369type HeaderLibraryInfo struct {
370}
371
372// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
373var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{})
374
Chris Parsons3c27ca32020-11-20 12:42:07 -0500375// FlagExporterInfo is a provider to propagate transitive library information
376// pertaining to exported include paths and flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700377type FlagExporterInfo struct {
Chris Parsons3c27ca32020-11-20 12:42:07 -0500378 IncludeDirs android.Paths // Include directories to be included with -I
379 SystemIncludeDirs android.Paths // System include directories to be included with -isystem
380 Flags []string // Exported raw flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700381 Deps android.Paths
382 GeneratedHeaders android.Paths
383}
384
385var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400386
387// flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
388func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
389
390 includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
391 systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
392
393 return FlagExporterInfo{
Chris Parsonsf60ecf02021-04-27 14:48:30 -0400394 IncludeDirs: android.FirstUniquePaths(includes),
395 SystemIncludeDirs: android.FirstUniquePaths(systemIncludes),
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400396 }
397}