blob: 84141e2989b77d3d99e8abddc5472c4dd5b35095 [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
Ivan Lozano3968d8f2020-12-14 11:27:52 -050017 // IsSanitizerEnabled returns whether a sanitizer is enabled.
18 IsSanitizerEnabled(t SanitizerType) bool
19
20 // IsSanitizerExplicitlyDisabled returns whether a sanitizer has been explicitly disabled (set to false) rather
21 // than left undefined.
22 IsSanitizerExplicitlyDisabled(t SanitizerType) bool
23
24 // SanitizeDep returns the value of the SanitizeDep flag, which is set if a module is a dependency of a
25 // sanitized module.
26 SanitizeDep() bool
27
28 // SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
29 SetSanitizer(t SanitizerType, b bool)
30
31 // SetSanitizerDep returns true if the module is statically linked.
32 SetSanitizeDep(b bool)
33
34 // StaticallyLinked returns true if the module is statically linked.
35 StaticallyLinked() bool
36
37 // SetInSanitizerDir sets the module installation to the sanitizer directory.
38 SetInSanitizerDir()
39
40 // SanitizeNever returns true if this module should never be sanitized.
41 SanitizeNever() bool
42
43 // SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
44 SanitizerSupported(t SanitizerType) bool
45
Ivan Lozanod7586b62021-04-01 09:49:36 -040046 // MinimalRuntimeDep returns true if this module needs to link the minimal UBSan runtime,
47 // either because it requires it or because a dependent module which requires it to be linked in this module.
48 MinimalRuntimeDep() bool
49
50 // UbsanRuntimeDep returns true if this module needs to link the full UBSan runtime,
51 // either because it requires it or because a dependent module which requires it to be linked in this module.
52 UbsanRuntimeDep() bool
53
54 // UbsanRuntimeNeeded returns true if the full UBSan runtime is required by this module.
55 UbsanRuntimeNeeded() bool
56
57 // MinimalRuntimeNeeded returns true if the minimal UBSan runtime is required by this module
58 MinimalRuntimeNeeded() bool
59
Ivan Lozano3968d8f2020-12-14 11:27:52 -050060 // SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
61 SanitizableDepTagChecker() SantizableDependencyTagChecker
62}
63
64// SantizableDependencyTagChecker functions check whether or not a dependency
65// tag can be sanitized. These functions should return true if the tag can be
66// sanitized, otherwise they should return false. These functions should also
67// handle all possible dependency tags in the dependency tree. For example,
68// Rust modules can depend on both Rust and CC libraries, so the Rust module
69// implementation should handle tags from both.
70type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
71
Ivan Lozanod7586b62021-04-01 09:49:36 -040072// Snapshottable defines those functions necessary for handling module snapshots.
73type Snapshottable interface {
74 // SnapshotHeaders returns a list of header paths provided by this module.
75 SnapshotHeaders() android.Paths
76
77 // ExcludeFromVendorSnapshot returns true if this module should be otherwise excluded from the vendor snapshot.
78 ExcludeFromVendorSnapshot() bool
79
80 // ExcludeFromRecoverySnapshot returns true if this module should be otherwise excluded from the recovery snapshot.
81 ExcludeFromRecoverySnapshot() bool
82
83 // SnapshotLibrary returns true if this module is a snapshot library.
84 IsSnapshotLibrary() bool
85
Justin Yun885a7de2021-06-29 20:34:53 +090086 // EffectiveLicenseFiles returns the list of License files for this module.
87 EffectiveLicenseFiles() android.Paths
88
Ivan Lozanod7586b62021-04-01 09:49:36 -040089 // SnapshotRuntimeLibs returns a list of libraries needed by this module at runtime but which aren't build dependencies.
90 SnapshotRuntimeLibs() []string
91
92 // SnapshotSharedLibs returns the list of shared library dependencies for this module.
93 SnapshotSharedLibs() []string
94
Justin Yun5e035862021-06-29 20:50:37 +090095 // SnapshotStaticLibs returns the list of static library dependencies for this module.
96 SnapshotStaticLibs() []string
97
Ivan Lozanod7586b62021-04-01 09:49:36 -040098 // IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
99 IsSnapshotPrebuilt() bool
100}
101
Chris Parsons3c27ca32020-11-20 12:42:07 -0500102// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
Ivan Lozano183a3212019-10-18 14:18:45 -0700103type LinkableInterface interface {
Ivan Lozanof9e21722020-12-02 09:00:51 -0500104 android.Module
Ivan Lozanod7586b62021-04-01 09:49:36 -0400105 Snapshottable
Ivan Lozanof9e21722020-12-02 09:00:51 -0500106
Ivan Lozano183a3212019-10-18 14:18:45 -0700107 Module() android.Module
108 CcLibrary() bool
109 CcLibraryInterface() bool
110
Ivan Lozanod7586b62021-04-01 09:49:36 -0400111 // BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
112 BaseModuleName() string
113
Ivan Lozano183a3212019-10-18 14:18:45 -0700114 OutputFile() android.OptionalPath
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400115 CoverageFiles() android.Paths
Ivan Lozano183a3212019-10-18 14:18:45 -0700116
Ivan Lozano2b262972019-11-21 12:30:50 -0800117 NonCcVariants() bool
118
Ivan Lozano52767be2019-10-18 14:49:46 -0700119 SelectedStl() string
Ivan Lozano183a3212019-10-18 14:18:45 -0700120
121 BuildStaticVariant() bool
122 BuildSharedVariant() bool
123 SetStatic()
124 SetShared()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500125 IsPrebuilt() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700126 Toc() android.OptionalPath
127
Jooyung Han624d35c2020-04-10 12:57:24 +0900128 Host() bool
129
Yifan Hong1b3348d2020-01-21 15:53:22 -0800130 InRamdisk() bool
131 OnlyInRamdisk() bool
132
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700133 InVendorRamdisk() bool
134 OnlyInVendorRamdisk() bool
135
Ivan Lozano52767be2019-10-18 14:49:46 -0700136 InRecovery() bool
137 OnlyInRecovery() bool
138
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500139 InVendor() bool
140
Colin Crossc511bc52020-04-07 16:50:32 +0000141 UseSdk() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400142
143 // IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
144 IsLlndk() bool
145
146 // IsLlndkPublic returns true only for LLNDK (public) libs.
147 IsLlndkPublic() bool
148
Ivan Lozanod7586b62021-04-01 09:49:36 -0400149 // HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
150 HasLlndkStubs() bool
151
Colin Cross1f3f1302021-04-26 18:37:44 -0700152 // NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
153 NeedsLlndkVariants() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400154
Colin Cross5271fea2021-04-27 13:06:04 -0700155 // NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
156 NeedsVendorPublicLibraryVariants() bool
157
Ivan Lozanod7586b62021-04-01 09:49:36 -0400158 //StubsVersion returns the stubs version for this module.
159 StubsVersion() string
160
161 // UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
162 // "product" and "vendor" variant modules return true for this function.
163 // When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
164 // "soc_specific: true" and more vendor installed modules are included here.
165 // When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
166 // "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700167 UseVndk() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400168
Jiyong Park7d55b612021-06-11 17:22:09 +0900169 // Bootstrap tests if this module is allowed to use non-APEX version of libraries.
170 Bootstrap() bool
171
Ivan Lozanod7586b62021-04-01 09:49:36 -0400172 // IsVndkSp returns true if this is a VNDK-SP module.
173 IsVndkSp() bool
174
Ivan Lozano52767be2019-10-18 14:49:46 -0700175 MustUseVendorVariant() bool
176 IsVndk() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500177 IsVndkExt() bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800178 IsVndkPrivate() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700179 HasVendorVariant() bool
Justin Yuncbca3732021-02-03 19:24:13 +0900180 HasProductVariant() bool
181 HasNonSystemVariants() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500182 InProduct() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700183
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400184 // SubName returns the modules SubName, used for image and NDK/SDK variations.
185 SubName() string
186
Ivan Lozano52767be2019-10-18 14:49:46 -0700187 SdkVersion() string
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900188 MinSdkVersion() string
Colin Crossc511bc52020-04-07 16:50:32 +0000189 AlwaysSdk() bool
Jiyong Park2286afd2020-06-16 21:58:53 +0900190 IsSdkVariant() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700191
Colin Cross1348ce32020-10-01 13:37:16 -0700192 SplitPerApiLevel() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500193
194 // SetPreventInstall sets the PreventInstall property to 'true' for this module.
195 SetPreventInstall()
196 // SetHideFromMake sets the HideFromMake property to 'true' for this module.
197 SetHideFromMake()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400198
199 // KernelHeadersDecorator returns true if this is a kernel headers decorator module.
200 // This is specific to cc and should always return false for all other packages.
201 KernelHeadersDecorator() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400202
203 // HiddenFromMake returns true if this module is hidden from Make.
204 HiddenFromMake() bool
205
206 // RelativeInstallPath returns the relative install path for this module.
207 RelativeInstallPath() string
208
209 // Binary returns true if this is a binary module.
210 Binary() bool
211
212 // Object returns true if this is an object module.
213 Object() bool
214
215 // Rlib returns true if this is an rlib module.
216 Rlib() bool
217
218 // Dylib returns true if this is an dylib module.
219 Dylib() bool
220
221 // Static returns true if this is a static library module.
222 Static() bool
223
224 // Shared returns true if this is a shared library module.
225 Shared() bool
226
227 // Header returns true if this is a library headers module.
228 Header() bool
229
Justin Yun5e035862021-06-29 20:50:37 +0900230 // StaticExecutable returns true if this is a binary module with "static_executable: true".
231 StaticExecutable() bool
232
Ivan Lozanod7586b62021-04-01 09:49:36 -0400233 // EverInstallable returns true if the module is ever installable
234 EverInstallable() bool
235
236 // PreventInstall returns true if this module is prevented from installation.
237 PreventInstall() bool
238
239 // InstallInData returns true if this module is installed in data.
240 InstallInData() bool
241
242 // Installable returns a bool pointer to the module installable property.
243 Installable() *bool
244
245 // Symlinks returns a list of symlinks that should be created for this module.
246 Symlinks() []string
247
248 // VndkVersion returns the VNDK version string for this module.
249 VndkVersion() string
Ivan Lozano183a3212019-10-18 14:18:45 -0700250}
251
Colin Cross6e511a92020-07-27 21:26:48 -0700252var (
Chris Parsons3c27ca32020-11-20 12:42:07 -0500253 // Dependency tag for crtbegin, an object file responsible for initialization.
Colin Cross6e511a92020-07-27 21:26:48 -0700254 CrtBeginDepTag = dependencyTag{name: "crtbegin"}
Chris Parsons3c27ca32020-11-20 12:42:07 -0500255 // Dependency tag for crtend, an object file responsible for program termination.
256 CrtEndDepTag = dependencyTag{name: "crtend"}
257 // Dependency tag for coverage library.
Colin Cross6e511a92020-07-27 21:26:48 -0700258 CoverageDepTag = dependencyTag{name: "coverage"}
259)
Ivan Lozano183a3212019-10-18 14:18:45 -0700260
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500261// GetImageVariantType returns the ImageVariantType string value for the given module
262// (these are defined in cc/image.go).
263func GetImageVariantType(c LinkableInterface) ImageVariantType {
264 if c.Host() {
265 return hostImageVariant
266 } else if c.InVendor() {
267 return vendorImageVariant
268 } else if c.InProduct() {
269 return productImageVariant
270 } else if c.InRamdisk() {
271 return ramdiskImageVariant
272 } else if c.InVendorRamdisk() {
273 return vendorRamdiskImageVariant
274 } else if c.InRecovery() {
275 return recoveryImageVariant
276 } else {
277 return coreImageVariant
278 }
279}
280
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400281// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
282// Returns an empty string if not a library dependency tag.
283func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
284 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
285 return libDepTag.makeSuffix
286 }
287 return ""
288}
289
Chris Parsons3c27ca32020-11-20 12:42:07 -0500290// SharedDepTag returns the dependency tag for any C++ shared libraries.
Colin Cross6e511a92020-07-27 21:26:48 -0700291func SharedDepTag() blueprint.DependencyTag {
292 return libraryDependencyTag{Kind: sharedLibraryDependency}
Ivan Lozano183a3212019-10-18 14:18:45 -0700293}
294
Chris Parsons3c27ca32020-11-20 12:42:07 -0500295// StaticDepTag returns the dependency tag for any C++ static libraries.
Ivan Lozano63bb7682021-03-23 15:53:44 -0400296func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
297 return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
298}
299
300// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
301func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
302 if tag, ok := depTag.(libraryDependencyTag); ok {
303 return tag.wholeStatic
304 }
305 return false
Colin Cross6e511a92020-07-27 21:26:48 -0700306}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700307
Chris Parsons3c27ca32020-11-20 12:42:07 -0500308// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
Zach Johnson3df4e632020-11-06 11:56:27 -0800309func HeaderDepTag() blueprint.DependencyTag {
310 return libraryDependencyTag{Kind: headerLibraryDependency}
311}
312
Chris Parsons3c27ca32020-11-20 12:42:07 -0500313// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700314type SharedLibraryInfo struct {
Liz Kammeref6dfea2021-06-08 15:37:09 -0400315 SharedLibrary android.Path
316 Target android.Target
Colin Cross0de8a1e2020-09-18 14:15:30 -0700317
Liz Kammeref6dfea2021-06-08 15:37:09 -0400318 TableOfContents android.OptionalPath
Colin Cross0de8a1e2020-09-18 14:15:30 -0700319
Liz Kammeref6dfea2021-06-08 15:37:09 -0400320 // should be obtained from static analogue
321 TransitiveStaticLibrariesForOrdering *android.DepSet
Colin Cross0de8a1e2020-09-18 14:15:30 -0700322}
323
324var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
325
Chris Parsons3c27ca32020-11-20 12:42:07 -0500326// SharedStubLibrary is a struct containing information about a stub shared library.
327// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
328// library in another APEX, it must depend on the stub version of that library.
329type SharedStubLibrary struct {
330 // The version of the stub (corresponding to the stable version of the shared library being
331 // stubbed).
Colin Cross0de8a1e2020-09-18 14:15:30 -0700332 Version string
333 SharedLibraryInfo SharedLibraryInfo
334 FlagExporterInfo FlagExporterInfo
335}
336
Chris Parsons3c27ca32020-11-20 12:42:07 -0500337// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
338// which are dependencies of a library.
339// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
340// library in another APEX, it must depend on the stub version of that library.
341type SharedLibraryStubsInfo struct {
342 SharedStubLibraries []SharedStubLibrary
Colin Cross0de8a1e2020-09-18 14:15:30 -0700343
Chris Parsons3c27ca32020-11-20 12:42:07 -0500344 IsLLNDK bool
345}
346
347var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{})
348
349// StaticLibraryInfo is a provider to propagate information about a static C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700350type StaticLibraryInfo struct {
351 StaticLibrary android.Path
352 Objects Objects
353 ReuseObjects Objects
354
355 // This isn't the actual transitive DepSet, shared library dependencies have been
356 // converted into static library analogues. It is only used to order the static
357 // library dependencies that were specified for the current module.
358 TransitiveStaticLibrariesForOrdering *android.DepSet
359}
360
361var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
362
Colin Cross649d8172020-12-10 12:30:21 -0800363// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
364type HeaderLibraryInfo struct {
365}
366
367// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
368var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{})
369
Chris Parsons3c27ca32020-11-20 12:42:07 -0500370// FlagExporterInfo is a provider to propagate transitive library information
371// pertaining to exported include paths and flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700372type FlagExporterInfo struct {
Chris Parsons3c27ca32020-11-20 12:42:07 -0500373 IncludeDirs android.Paths // Include directories to be included with -I
374 SystemIncludeDirs android.Paths // System include directories to be included with -isystem
375 Flags []string // Exported raw flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700376 Deps android.Paths
377 GeneratedHeaders android.Paths
378}
379
380var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400381
382// flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
383func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
384
385 includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
386 systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
387
388 return FlagExporterInfo{
Chris Parsonsf60ecf02021-04-27 14:48:30 -0400389 IncludeDirs: android.FirstUniquePaths(includes),
390 SystemIncludeDirs: android.FirstUniquePaths(systemIncludes),
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400391 }
392}