blob: 557f5d2b314c942b7523a4961242cfcfa3aae27c [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"
Ivan Lozano0f9963e2023-02-06 13:31:02 -05006 "android/soong/fuzz"
Kiyoung Kim48f37782021-07-07 12:42:39 +09007 "android/soong/snapshot"
Colin Cross6e511a92020-07-27 21:26:48 -07008
9 "github.com/google/blueprint"
Ivan Lozano183a3212019-10-18 14:18:45 -070010)
11
Ivan Lozano3968d8f2020-12-14 11:27:52 -050012// PlatformSanitizeable is an interface for sanitizing platform modules.
13type PlatformSanitizeable interface {
14 LinkableInterface
15
16 // SanitizePropDefined returns whether the Sanitizer properties struct for this module is defined.
17 SanitizePropDefined() bool
18
Ivan Lozano3968d8f2020-12-14 11:27:52 -050019 // IsSanitizerEnabled returns whether a sanitizer is enabled.
20 IsSanitizerEnabled(t SanitizerType) bool
21
22 // IsSanitizerExplicitlyDisabled returns whether a sanitizer has been explicitly disabled (set to false) rather
23 // than left undefined.
24 IsSanitizerExplicitlyDisabled(t SanitizerType) bool
25
Ivan Lozano3968d8f2020-12-14 11:27:52 -050026 // SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
27 SetSanitizer(t SanitizerType, b bool)
28
Ivan Lozano3968d8f2020-12-14 11:27:52 -050029 // StaticallyLinked returns true if the module is statically linked.
30 StaticallyLinked() bool
31
32 // SetInSanitizerDir sets the module installation to the sanitizer directory.
33 SetInSanitizerDir()
34
35 // SanitizeNever returns true if this module should never be sanitized.
36 SanitizeNever() bool
37
38 // SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
39 SanitizerSupported(t SanitizerType) bool
40
Ivan Lozanod7586b62021-04-01 09:49:36 -040041 // MinimalRuntimeDep returns true if this module needs to link the minimal UBSan runtime,
42 // either because it requires it or because a dependent module which requires it to be linked in this module.
43 MinimalRuntimeDep() bool
44
45 // UbsanRuntimeDep returns true if this module needs to link the full UBSan runtime,
46 // either because it requires it or because a dependent module which requires it to be linked in this module.
47 UbsanRuntimeDep() bool
48
49 // UbsanRuntimeNeeded returns true if the full UBSan runtime is required by this module.
50 UbsanRuntimeNeeded() bool
51
52 // MinimalRuntimeNeeded returns true if the minimal UBSan runtime is required by this module
53 MinimalRuntimeNeeded() bool
54
Ivan Lozano3968d8f2020-12-14 11:27:52 -050055 // SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
56 SanitizableDepTagChecker() SantizableDependencyTagChecker
57}
58
59// SantizableDependencyTagChecker functions check whether or not a dependency
60// tag can be sanitized. These functions should return true if the tag can be
61// sanitized, otherwise they should return false. These functions should also
62// handle all possible dependency tags in the dependency tree. For example,
63// Rust modules can depend on both Rust and CC libraries, so the Rust module
64// implementation should handle tags from both.
65type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
66
Ivan Lozanod7586b62021-04-01 09:49:36 -040067// Snapshottable defines those functions necessary for handling module snapshots.
68type Snapshottable interface {
Kiyoung Kim48f37782021-07-07 12:42:39 +090069 snapshot.VendorSnapshotModuleInterface
70 snapshot.RecoverySnapshotModuleInterface
71
Ivan Lozanod7586b62021-04-01 09:49:36 -040072 // SnapshotHeaders returns a list of header paths provided by this module.
73 SnapshotHeaders() android.Paths
74
Ivan Lozanod7586b62021-04-01 09:49:36 -040075 // SnapshotLibrary returns true if this module is a snapshot library.
76 IsSnapshotLibrary() bool
77
Justin Yun885a7de2021-06-29 20:34:53 +090078 // EffectiveLicenseFiles returns the list of License files for this module.
79 EffectiveLicenseFiles() android.Paths
80
Ivan Lozanod7586b62021-04-01 09:49:36 -040081 // SnapshotRuntimeLibs returns a list of libraries needed by this module at runtime but which aren't build dependencies.
82 SnapshotRuntimeLibs() []string
83
84 // SnapshotSharedLibs returns the list of shared library dependencies for this module.
85 SnapshotSharedLibs() []string
86
Justin Yun5e035862021-06-29 20:50:37 +090087 // SnapshotStaticLibs returns the list of static library dependencies for this module.
88 SnapshotStaticLibs() []string
89
Ivan Lozanod7586b62021-04-01 09:49:36 -040090 // IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
91 IsSnapshotPrebuilt() bool
92}
93
Chris Parsons3c27ca32020-11-20 12:42:07 -050094// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
Ivan Lozano183a3212019-10-18 14:18:45 -070095type LinkableInterface interface {
Ivan Lozanof9e21722020-12-02 09:00:51 -050096 android.Module
Ivan Lozanod7586b62021-04-01 09:49:36 -040097 Snapshottable
Ivan Lozanof9e21722020-12-02 09:00:51 -050098
Ivan Lozano183a3212019-10-18 14:18:45 -070099 Module() android.Module
100 CcLibrary() bool
101 CcLibraryInterface() bool
102
Ivan Lozanod7586b62021-04-01 09:49:36 -0400103 // BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
104 BaseModuleName() string
105
Ivan Lozano183a3212019-10-18 14:18:45 -0700106 OutputFile() android.OptionalPath
Ivan Lozano39b0bf02021-10-14 12:22:09 -0400107 UnstrippedOutputFile() android.Path
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400108 CoverageFiles() android.Paths
Ivan Lozano183a3212019-10-18 14:18:45 -0700109
Ivan Lozano7f67c2a2022-06-27 16:00:26 -0400110 // CoverageOutputFile returns the output archive of gcno coverage information files.
111 CoverageOutputFile() android.OptionalPath
112
Ivan Lozano2b262972019-11-21 12:30:50 -0800113 NonCcVariants() bool
114
Ivan Lozano52767be2019-10-18 14:49:46 -0700115 SelectedStl() string
Ivan Lozano183a3212019-10-18 14:18:45 -0700116
117 BuildStaticVariant() bool
118 BuildSharedVariant() bool
119 SetStatic()
120 SetShared()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500121 IsPrebuilt() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700122 Toc() android.OptionalPath
123
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500124 // IsFuzzModule returns true if this a *_fuzz module.
125 IsFuzzModule() bool
126
127 // FuzzPackagedModule returns the fuzz.FuzzPackagedModule for this module.
128 // Expects that IsFuzzModule returns true.
129 FuzzPackagedModule() fuzz.FuzzPackagedModule
130
131 // FuzzSharedLibraries returns the shared library dependencies for this module.
132 // Expects that IsFuzzModule returns true.
Hamzeh Zawawy38917492023-04-05 22:08:46 +0000133 FuzzSharedLibraries() android.RuleBuilderInstalls
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500134
Yi-Yo Chiang36d8e4e2021-07-02 21:21:13 +0800135 Device() bool
Jooyung Han624d35c2020-04-10 12:57:24 +0900136 Host() bool
137
Yifan Hong1b3348d2020-01-21 15:53:22 -0800138 InRamdisk() bool
139 OnlyInRamdisk() bool
140
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700141 InVendorRamdisk() bool
142 OnlyInVendorRamdisk() bool
143
Ivan Lozano52767be2019-10-18 14:49:46 -0700144 InRecovery() bool
145 OnlyInRecovery() bool
146
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500147 InVendor() bool
148
Colin Crossc511bc52020-04-07 16:50:32 +0000149 UseSdk() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400150
Ivan Lozano7f67c2a2022-06-27 16:00:26 -0400151 // IsNdk returns true if the library is in the configs known NDK list.
152 IsNdk(config android.Config) bool
153
154 // IsStubs returns true if the this is a stubs library.
155 IsStubs() bool
156
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400157 // IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
158 IsLlndk() bool
159
160 // IsLlndkPublic returns true only for LLNDK (public) libs.
161 IsLlndkPublic() bool
162
Ivan Lozanod7586b62021-04-01 09:49:36 -0400163 // HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
164 HasLlndkStubs() bool
165
Colin Cross1f3f1302021-04-26 18:37:44 -0700166 // NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
167 NeedsLlndkVariants() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400168
Colin Cross5271fea2021-04-27 13:06:04 -0700169 // NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
170 NeedsVendorPublicLibraryVariants() bool
171
Ivan Lozanod7586b62021-04-01 09:49:36 -0400172 //StubsVersion returns the stubs version for this module.
173 StubsVersion() string
174
175 // UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
176 // "product" and "vendor" variant modules return true for this function.
177 // When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
178 // "soc_specific: true" and more vendor installed modules are included here.
179 // When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
180 // "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700181 UseVndk() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400182
Jiyong Park7d55b612021-06-11 17:22:09 +0900183 // Bootstrap tests if this module is allowed to use non-APEX version of libraries.
184 Bootstrap() bool
185
Ivan Lozanod7586b62021-04-01 09:49:36 -0400186 // IsVndkSp returns true if this is a VNDK-SP module.
187 IsVndkSp() bool
188
Ivan Lozano52767be2019-10-18 14:49:46 -0700189 MustUseVendorVariant() bool
190 IsVndk() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500191 IsVndkExt() bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800192 IsVndkPrivate() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400193 IsVendorPublicLibrary() bool
194 IsVndkPrebuiltLibrary() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700195 HasVendorVariant() bool
Justin Yuncbca3732021-02-03 19:24:13 +0900196 HasProductVariant() bool
197 HasNonSystemVariants() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400198 ProductSpecific() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500199 InProduct() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400200 SdkAndPlatformVariantVisibleToMake() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700201
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400202 // SubName returns the modules SubName, used for image and NDK/SDK variations.
203 SubName() string
204
Ivan Lozano52767be2019-10-18 14:49:46 -0700205 SdkVersion() string
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900206 MinSdkVersion() string
Colin Crossc511bc52020-04-07 16:50:32 +0000207 AlwaysSdk() bool
Jiyong Park2286afd2020-06-16 21:58:53 +0900208 IsSdkVariant() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700209
Colin Cross1348ce32020-10-01 13:37:16 -0700210 SplitPerApiLevel() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500211
212 // SetPreventInstall sets the PreventInstall property to 'true' for this module.
213 SetPreventInstall()
214 // SetHideFromMake sets the HideFromMake property to 'true' for this module.
215 SetHideFromMake()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400216
217 // KernelHeadersDecorator returns true if this is a kernel headers decorator module.
218 // This is specific to cc and should always return false for all other packages.
219 KernelHeadersDecorator() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400220
221 // HiddenFromMake returns true if this module is hidden from Make.
222 HiddenFromMake() bool
223
224 // RelativeInstallPath returns the relative install path for this module.
225 RelativeInstallPath() string
226
227 // Binary returns true if this is a binary module.
228 Binary() bool
229
230 // Object returns true if this is an object module.
231 Object() bool
232
233 // Rlib returns true if this is an rlib module.
234 Rlib() bool
235
236 // Dylib returns true if this is an dylib module.
237 Dylib() bool
238
239 // Static returns true if this is a static library module.
240 Static() bool
241
242 // Shared returns true if this is a shared library module.
243 Shared() bool
244
245 // Header returns true if this is a library headers module.
246 Header() bool
247
Justin Yun5e035862021-06-29 20:50:37 +0900248 // StaticExecutable returns true if this is a binary module with "static_executable: true".
249 StaticExecutable() bool
250
Ivan Lozanod7586b62021-04-01 09:49:36 -0400251 // EverInstallable returns true if the module is ever installable
252 EverInstallable() bool
253
254 // PreventInstall returns true if this module is prevented from installation.
255 PreventInstall() bool
256
257 // InstallInData returns true if this module is installed in data.
258 InstallInData() bool
259
260 // Installable returns a bool pointer to the module installable property.
261 Installable() *bool
262
263 // Symlinks returns a list of symlinks that should be created for this module.
264 Symlinks() []string
265
266 // VndkVersion returns the VNDK version string for this module.
267 VndkVersion() string
Jihoon Kangf78a8902022-09-01 22:47:07 +0000268
269 // Partition returns the partition string for this module.
270 Partition() string
Ivan Lozano0f9963e2023-02-06 13:31:02 -0500271
272 // FuzzModule returns the fuzz.FuzzModule associated with the module.
273 FuzzModuleStruct() fuzz.FuzzModule
Ivan Lozano183a3212019-10-18 14:18:45 -0700274}
275
Colin Cross6e511a92020-07-27 21:26:48 -0700276var (
Chris Parsons3c27ca32020-11-20 12:42:07 -0500277 // Dependency tag for crtbegin, an object file responsible for initialization.
Colin Cross6e511a92020-07-27 21:26:48 -0700278 CrtBeginDepTag = dependencyTag{name: "crtbegin"}
Chris Parsons3c27ca32020-11-20 12:42:07 -0500279 // Dependency tag for crtend, an object file responsible for program termination.
280 CrtEndDepTag = dependencyTag{name: "crtend"}
281 // Dependency tag for coverage library.
Colin Cross6e511a92020-07-27 21:26:48 -0700282 CoverageDepTag = dependencyTag{name: "coverage"}
283)
Ivan Lozano183a3212019-10-18 14:18:45 -0700284
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500285// GetImageVariantType returns the ImageVariantType string value for the given module
286// (these are defined in cc/image.go).
287func GetImageVariantType(c LinkableInterface) ImageVariantType {
288 if c.Host() {
289 return hostImageVariant
290 } else if c.InVendor() {
291 return vendorImageVariant
292 } else if c.InProduct() {
293 return productImageVariant
294 } else if c.InRamdisk() {
295 return ramdiskImageVariant
296 } else if c.InVendorRamdisk() {
297 return vendorRamdiskImageVariant
298 } else if c.InRecovery() {
299 return recoveryImageVariant
300 } else {
301 return coreImageVariant
302 }
303}
304
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400305// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
306// Returns an empty string if not a library dependency tag.
307func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
308 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
309 return libDepTag.makeSuffix
310 }
311 return ""
312}
313
Chris Parsons3c27ca32020-11-20 12:42:07 -0500314// SharedDepTag returns the dependency tag for any C++ shared libraries.
Colin Cross6e511a92020-07-27 21:26:48 -0700315func SharedDepTag() blueprint.DependencyTag {
316 return libraryDependencyTag{Kind: sharedLibraryDependency}
Ivan Lozano183a3212019-10-18 14:18:45 -0700317}
318
Chris Parsons3c27ca32020-11-20 12:42:07 -0500319// StaticDepTag returns the dependency tag for any C++ static libraries.
Ivan Lozano63bb7682021-03-23 15:53:44 -0400320func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
321 return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
322}
323
324// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
325func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
326 if tag, ok := depTag.(libraryDependencyTag); ok {
327 return tag.wholeStatic
328 }
329 return false
Colin Cross6e511a92020-07-27 21:26:48 -0700330}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700331
Chris Parsons3c27ca32020-11-20 12:42:07 -0500332// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
Zach Johnson3df4e632020-11-06 11:56:27 -0800333func HeaderDepTag() blueprint.DependencyTag {
334 return libraryDependencyTag{Kind: headerLibraryDependency}
335}
336
Chris Parsons3c27ca32020-11-20 12:42:07 -0500337// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700338type SharedLibraryInfo struct {
Liz Kammeref6dfea2021-06-08 15:37:09 -0400339 SharedLibrary android.Path
340 Target android.Target
Colin Cross0de8a1e2020-09-18 14:15:30 -0700341
Liz Kammeref6dfea2021-06-08 15:37:09 -0400342 TableOfContents android.OptionalPath
Colin Cross0de8a1e2020-09-18 14:15:30 -0700343
Liz Kammeref6dfea2021-06-08 15:37:09 -0400344 // should be obtained from static analogue
345 TransitiveStaticLibrariesForOrdering *android.DepSet
Colin Cross0de8a1e2020-09-18 14:15:30 -0700346}
347
348var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
349
Chris Parsons3c27ca32020-11-20 12:42:07 -0500350// SharedStubLibrary is a struct containing information about a stub shared library.
351// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
352// library in another APEX, it must depend on the stub version of that library.
353type SharedStubLibrary struct {
354 // The version of the stub (corresponding to the stable version of the shared library being
355 // stubbed).
Colin Cross0de8a1e2020-09-18 14:15:30 -0700356 Version string
357 SharedLibraryInfo SharedLibraryInfo
358 FlagExporterInfo FlagExporterInfo
359}
360
Chris Parsons3c27ca32020-11-20 12:42:07 -0500361// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
362// which are dependencies of a library.
363// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
364// library in another APEX, it must depend on the stub version of that library.
365type SharedLibraryStubsInfo struct {
366 SharedStubLibraries []SharedStubLibrary
Colin Cross0de8a1e2020-09-18 14:15:30 -0700367
Chris Parsons3c27ca32020-11-20 12:42:07 -0500368 IsLLNDK bool
369}
370
371var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{})
372
373// StaticLibraryInfo is a provider to propagate information about a static C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700374type StaticLibraryInfo struct {
375 StaticLibrary android.Path
376 Objects Objects
377 ReuseObjects Objects
378
Colin Crossa2bcf2c2022-02-11 13:11:55 -0800379 // A static library may contain prebuilt static libraries included with whole_static_libs
380 // that won't appear in Objects. They are transitively available in
381 // WholeStaticLibsFromPrebuilts.
382 WholeStaticLibsFromPrebuilts android.Paths
383
Colin Cross0de8a1e2020-09-18 14:15:30 -0700384 // This isn't the actual transitive DepSet, shared library dependencies have been
385 // converted into static library analogues. It is only used to order the static
386 // library dependencies that were specified for the current module.
387 TransitiveStaticLibrariesForOrdering *android.DepSet
388}
389
390var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
391
Colin Cross649d8172020-12-10 12:30:21 -0800392// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
393type HeaderLibraryInfo struct {
394}
395
396// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
397var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{})
398
Chris Parsons3c27ca32020-11-20 12:42:07 -0500399// FlagExporterInfo is a provider to propagate transitive library information
400// pertaining to exported include paths and flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700401type FlagExporterInfo struct {
Chris Parsons3c27ca32020-11-20 12:42:07 -0500402 IncludeDirs android.Paths // Include directories to be included with -I
403 SystemIncludeDirs android.Paths // System include directories to be included with -isystem
404 Flags []string // Exported raw flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700405 Deps android.Paths
406 GeneratedHeaders android.Paths
407}
408
409var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400410
411// flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
412func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
413
414 includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
415 systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
Liz Kammereb2d6d12021-12-06 14:56:25 -0500416 headers := android.PathsForBazelOut(ctx, ccInfo.Headers)
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400417
418 return FlagExporterInfo{
Chris Parsonsf60ecf02021-04-27 14:48:30 -0400419 IncludeDirs: android.FirstUniquePaths(includes),
420 SystemIncludeDirs: android.FirstUniquePaths(systemIncludes),
Liz Kammereb2d6d12021-12-06 14:56:25 -0500421 GeneratedHeaders: headers,
422 // necessary to ensure generated headers are considered implicit deps of dependent actions
423 Deps: headers,
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400424 }
425}