blob: 2316d865c1a6b9471258866cd466f8ca819bf54b [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"
Kiyoung Kim48f37782021-07-07 12:42:39 +09006 "android/soong/snapshot"
Colin Cross6e511a92020-07-27 21:26:48 -07007
8 "github.com/google/blueprint"
Ivan Lozano183a3212019-10-18 14:18:45 -07009)
10
Ivan Lozano3968d8f2020-12-14 11:27:52 -050011// PlatformSanitizeable is an interface for sanitizing platform modules.
12type PlatformSanitizeable interface {
13 LinkableInterface
14
15 // SanitizePropDefined returns whether the Sanitizer properties struct for this module is defined.
16 SanitizePropDefined() bool
17
Ivan Lozano3968d8f2020-12-14 11:27:52 -050018 // IsSanitizerEnabled returns whether a sanitizer is enabled.
19 IsSanitizerEnabled(t SanitizerType) bool
20
21 // IsSanitizerExplicitlyDisabled returns whether a sanitizer has been explicitly disabled (set to false) rather
22 // than left undefined.
23 IsSanitizerExplicitlyDisabled(t SanitizerType) bool
24
Ivan Lozano3968d8f2020-12-14 11:27:52 -050025 // SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
26 SetSanitizer(t SanitizerType, b bool)
27
Ivan Lozano3968d8f2020-12-14 11:27:52 -050028 // StaticallyLinked returns true if the module is statically linked.
29 StaticallyLinked() bool
30
31 // SetInSanitizerDir sets the module installation to the sanitizer directory.
32 SetInSanitizerDir()
33
34 // SanitizeNever returns true if this module should never be sanitized.
35 SanitizeNever() bool
36
37 // SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
38 SanitizerSupported(t SanitizerType) bool
39
Ivan Lozanod7586b62021-04-01 09:49:36 -040040 // MinimalRuntimeDep returns true if this module needs to link the minimal UBSan runtime,
41 // either because it requires it or because a dependent module which requires it to be linked in this module.
42 MinimalRuntimeDep() bool
43
44 // UbsanRuntimeDep returns true if this module needs to link the full UBSan runtime,
45 // either because it requires it or because a dependent module which requires it to be linked in this module.
46 UbsanRuntimeDep() bool
47
48 // UbsanRuntimeNeeded returns true if the full UBSan runtime is required by this module.
49 UbsanRuntimeNeeded() bool
50
51 // MinimalRuntimeNeeded returns true if the minimal UBSan runtime is required by this module
52 MinimalRuntimeNeeded() bool
53
Ivan Lozano3968d8f2020-12-14 11:27:52 -050054 // SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
55 SanitizableDepTagChecker() SantizableDependencyTagChecker
56}
57
58// SantizableDependencyTagChecker functions check whether or not a dependency
59// tag can be sanitized. These functions should return true if the tag can be
60// sanitized, otherwise they should return false. These functions should also
61// handle all possible dependency tags in the dependency tree. For example,
62// Rust modules can depend on both Rust and CC libraries, so the Rust module
63// implementation should handle tags from both.
64type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
65
Ivan Lozanod7586b62021-04-01 09:49:36 -040066// Snapshottable defines those functions necessary for handling module snapshots.
67type Snapshottable interface {
Kiyoung Kim48f37782021-07-07 12:42:39 +090068 snapshot.VendorSnapshotModuleInterface
69 snapshot.RecoverySnapshotModuleInterface
70
Ivan Lozanod7586b62021-04-01 09:49:36 -040071 // SnapshotHeaders returns a list of header paths provided by this module.
72 SnapshotHeaders() android.Paths
73
Ivan Lozanod7586b62021-04-01 09:49:36 -040074 // SnapshotLibrary returns true if this module is a snapshot library.
75 IsSnapshotLibrary() bool
76
Justin Yun885a7de2021-06-29 20:34:53 +090077 // EffectiveLicenseFiles returns the list of License files for this module.
78 EffectiveLicenseFiles() android.Paths
79
Ivan Lozanod7586b62021-04-01 09:49:36 -040080 // SnapshotRuntimeLibs returns a list of libraries needed by this module at runtime but which aren't build dependencies.
81 SnapshotRuntimeLibs() []string
82
83 // SnapshotSharedLibs returns the list of shared library dependencies for this module.
84 SnapshotSharedLibs() []string
85
Justin Yun5e035862021-06-29 20:50:37 +090086 // SnapshotStaticLibs returns the list of static library dependencies for this module.
87 SnapshotStaticLibs() []string
88
Ivan Lozanod7586b62021-04-01 09:49:36 -040089 // IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
90 IsSnapshotPrebuilt() bool
91}
92
Chris Parsons3c27ca32020-11-20 12:42:07 -050093// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
Ivan Lozano183a3212019-10-18 14:18:45 -070094type LinkableInterface interface {
Ivan Lozanof9e21722020-12-02 09:00:51 -050095 android.Module
Ivan Lozanod7586b62021-04-01 09:49:36 -040096 Snapshottable
Ivan Lozanof9e21722020-12-02 09:00:51 -050097
Ivan Lozano183a3212019-10-18 14:18:45 -070098 Module() android.Module
99 CcLibrary() bool
100 CcLibraryInterface() bool
101
Ivan Lozanod7586b62021-04-01 09:49:36 -0400102 // BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
103 BaseModuleName() string
104
Ivan Lozano183a3212019-10-18 14:18:45 -0700105 OutputFile() android.OptionalPath
Ivan Lozano39b0bf02021-10-14 12:22:09 -0400106 UnstrippedOutputFile() android.Path
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400107 CoverageFiles() android.Paths
Ivan Lozano183a3212019-10-18 14:18:45 -0700108
Ivan Lozano7f67c2a2022-06-27 16:00:26 -0400109 // CoverageOutputFile returns the output archive of gcno coverage information files.
110 CoverageOutputFile() android.OptionalPath
111
Ivan Lozano2b262972019-11-21 12:30:50 -0800112 NonCcVariants() bool
113
Ivan Lozano52767be2019-10-18 14:49:46 -0700114 SelectedStl() string
Ivan Lozano183a3212019-10-18 14:18:45 -0700115
116 BuildStaticVariant() bool
117 BuildSharedVariant() bool
118 SetStatic()
119 SetShared()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500120 IsPrebuilt() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700121 Toc() android.OptionalPath
122
Yi-Yo Chiang36d8e4e2021-07-02 21:21:13 +0800123 Device() bool
Jooyung Han624d35c2020-04-10 12:57:24 +0900124 Host() bool
125
Yifan Hong1b3348d2020-01-21 15:53:22 -0800126 InRamdisk() bool
127 OnlyInRamdisk() bool
128
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700129 InVendorRamdisk() bool
130 OnlyInVendorRamdisk() bool
131
Ivan Lozano52767be2019-10-18 14:49:46 -0700132 InRecovery() bool
133 OnlyInRecovery() bool
134
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500135 InVendor() bool
136
Colin Crossc511bc52020-04-07 16:50:32 +0000137 UseSdk() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400138
Ivan Lozano7f67c2a2022-06-27 16:00:26 -0400139 // IsNdk returns true if the library is in the configs known NDK list.
140 IsNdk(config android.Config) bool
141
142 // IsStubs returns true if the this is a stubs library.
143 IsStubs() bool
144
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400145 // IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
146 IsLlndk() bool
147
148 // IsLlndkPublic returns true only for LLNDK (public) libs.
149 IsLlndkPublic() bool
150
Ivan Lozanod7586b62021-04-01 09:49:36 -0400151 // HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
152 HasLlndkStubs() bool
153
Colin Cross1f3f1302021-04-26 18:37:44 -0700154 // NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
155 NeedsLlndkVariants() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400156
Colin Cross5271fea2021-04-27 13:06:04 -0700157 // NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
158 NeedsVendorPublicLibraryVariants() bool
159
Ivan Lozanod7586b62021-04-01 09:49:36 -0400160 //StubsVersion returns the stubs version for this module.
161 StubsVersion() string
162
163 // UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
164 // "product" and "vendor" variant modules return true for this function.
165 // When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
166 // "soc_specific: true" and more vendor installed modules are included here.
167 // When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
168 // "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700169 UseVndk() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400170
Jiyong Park7d55b612021-06-11 17:22:09 +0900171 // Bootstrap tests if this module is allowed to use non-APEX version of libraries.
172 Bootstrap() bool
173
Ivan Lozanod7586b62021-04-01 09:49:36 -0400174 // IsVndkSp returns true if this is a VNDK-SP module.
175 IsVndkSp() bool
176
Ivan Lozano52767be2019-10-18 14:49:46 -0700177 MustUseVendorVariant() bool
178 IsVndk() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500179 IsVndkExt() bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800180 IsVndkPrivate() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400181 IsVendorPublicLibrary() bool
182 IsVndkPrebuiltLibrary() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700183 HasVendorVariant() bool
Justin Yuncbca3732021-02-03 19:24:13 +0900184 HasProductVariant() bool
185 HasNonSystemVariants() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400186 ProductSpecific() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500187 InProduct() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400188 SdkAndPlatformVariantVisibleToMake() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700189
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400190 // SubName returns the modules SubName, used for image and NDK/SDK variations.
191 SubName() string
192
Ivan Lozano52767be2019-10-18 14:49:46 -0700193 SdkVersion() string
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900194 MinSdkVersion() string
Colin Crossc511bc52020-04-07 16:50:32 +0000195 AlwaysSdk() bool
Jiyong Park2286afd2020-06-16 21:58:53 +0900196 IsSdkVariant() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700197
Colin Cross1348ce32020-10-01 13:37:16 -0700198 SplitPerApiLevel() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500199
200 // SetPreventInstall sets the PreventInstall property to 'true' for this module.
201 SetPreventInstall()
202 // SetHideFromMake sets the HideFromMake property to 'true' for this module.
203 SetHideFromMake()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400204
205 // KernelHeadersDecorator returns true if this is a kernel headers decorator module.
206 // This is specific to cc and should always return false for all other packages.
207 KernelHeadersDecorator() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400208
209 // HiddenFromMake returns true if this module is hidden from Make.
210 HiddenFromMake() bool
211
212 // RelativeInstallPath returns the relative install path for this module.
213 RelativeInstallPath() string
214
215 // Binary returns true if this is a binary module.
216 Binary() bool
217
218 // Object returns true if this is an object module.
219 Object() bool
220
221 // Rlib returns true if this is an rlib module.
222 Rlib() bool
223
224 // Dylib returns true if this is an dylib module.
225 Dylib() bool
226
227 // Static returns true if this is a static library module.
228 Static() bool
229
230 // Shared returns true if this is a shared library module.
231 Shared() bool
232
233 // Header returns true if this is a library headers module.
234 Header() bool
235
Justin Yun5e035862021-06-29 20:50:37 +0900236 // StaticExecutable returns true if this is a binary module with "static_executable: true".
237 StaticExecutable() bool
238
Ivan Lozanod7586b62021-04-01 09:49:36 -0400239 // EverInstallable returns true if the module is ever installable
240 EverInstallable() bool
241
242 // PreventInstall returns true if this module is prevented from installation.
243 PreventInstall() bool
244
245 // InstallInData returns true if this module is installed in data.
246 InstallInData() bool
247
248 // Installable returns a bool pointer to the module installable property.
249 Installable() *bool
250
251 // Symlinks returns a list of symlinks that should be created for this module.
252 Symlinks() []string
253
254 // VndkVersion returns the VNDK version string for this module.
255 VndkVersion() string
Ivan Lozano183a3212019-10-18 14:18:45 -0700256}
257
Colin Cross6e511a92020-07-27 21:26:48 -0700258var (
Chris Parsons3c27ca32020-11-20 12:42:07 -0500259 // Dependency tag for crtbegin, an object file responsible for initialization.
Colin Cross6e511a92020-07-27 21:26:48 -0700260 CrtBeginDepTag = dependencyTag{name: "crtbegin"}
Chris Parsons3c27ca32020-11-20 12:42:07 -0500261 // Dependency tag for crtend, an object file responsible for program termination.
262 CrtEndDepTag = dependencyTag{name: "crtend"}
263 // Dependency tag for coverage library.
Colin Cross6e511a92020-07-27 21:26:48 -0700264 CoverageDepTag = dependencyTag{name: "coverage"}
265)
Ivan Lozano183a3212019-10-18 14:18:45 -0700266
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500267// GetImageVariantType returns the ImageVariantType string value for the given module
268// (these are defined in cc/image.go).
269func GetImageVariantType(c LinkableInterface) ImageVariantType {
270 if c.Host() {
271 return hostImageVariant
272 } else if c.InVendor() {
273 return vendorImageVariant
274 } else if c.InProduct() {
275 return productImageVariant
276 } else if c.InRamdisk() {
277 return ramdiskImageVariant
278 } else if c.InVendorRamdisk() {
279 return vendorRamdiskImageVariant
280 } else if c.InRecovery() {
281 return recoveryImageVariant
282 } else {
283 return coreImageVariant
284 }
285}
286
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400287// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
288// Returns an empty string if not a library dependency tag.
289func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
290 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
291 return libDepTag.makeSuffix
292 }
293 return ""
294}
295
Chris Parsons3c27ca32020-11-20 12:42:07 -0500296// SharedDepTag returns the dependency tag for any C++ shared libraries.
Colin Cross6e511a92020-07-27 21:26:48 -0700297func SharedDepTag() blueprint.DependencyTag {
298 return libraryDependencyTag{Kind: sharedLibraryDependency}
Ivan Lozano183a3212019-10-18 14:18:45 -0700299}
300
Chris Parsons3c27ca32020-11-20 12:42:07 -0500301// StaticDepTag returns the dependency tag for any C++ static libraries.
Ivan Lozano63bb7682021-03-23 15:53:44 -0400302func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
303 return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
304}
305
306// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
307func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
308 if tag, ok := depTag.(libraryDependencyTag); ok {
309 return tag.wholeStatic
310 }
311 return false
Colin Cross6e511a92020-07-27 21:26:48 -0700312}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700313
Chris Parsons3c27ca32020-11-20 12:42:07 -0500314// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
Zach Johnson3df4e632020-11-06 11:56:27 -0800315func HeaderDepTag() blueprint.DependencyTag {
316 return libraryDependencyTag{Kind: headerLibraryDependency}
317}
318
Chris Parsons3c27ca32020-11-20 12:42:07 -0500319// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700320type SharedLibraryInfo struct {
Liz Kammeref6dfea2021-06-08 15:37:09 -0400321 SharedLibrary android.Path
322 Target android.Target
Colin Cross0de8a1e2020-09-18 14:15:30 -0700323
Liz Kammeref6dfea2021-06-08 15:37:09 -0400324 TableOfContents android.OptionalPath
Colin Cross0de8a1e2020-09-18 14:15:30 -0700325
Liz Kammeref6dfea2021-06-08 15:37:09 -0400326 // should be obtained from static analogue
327 TransitiveStaticLibrariesForOrdering *android.DepSet
Colin Cross0de8a1e2020-09-18 14:15:30 -0700328}
329
330var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
331
Chris Parsons3c27ca32020-11-20 12:42:07 -0500332// SharedStubLibrary is a struct containing information about a stub shared library.
333// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
334// library in another APEX, it must depend on the stub version of that library.
335type SharedStubLibrary struct {
336 // The version of the stub (corresponding to the stable version of the shared library being
337 // stubbed).
Colin Cross0de8a1e2020-09-18 14:15:30 -0700338 Version string
339 SharedLibraryInfo SharedLibraryInfo
340 FlagExporterInfo FlagExporterInfo
341}
342
Chris Parsons3c27ca32020-11-20 12:42:07 -0500343// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
344// which are dependencies of a library.
345// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
346// library in another APEX, it must depend on the stub version of that library.
347type SharedLibraryStubsInfo struct {
348 SharedStubLibraries []SharedStubLibrary
Colin Cross0de8a1e2020-09-18 14:15:30 -0700349
Chris Parsons3c27ca32020-11-20 12:42:07 -0500350 IsLLNDK bool
351}
352
353var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{})
354
355// StaticLibraryInfo is a provider to propagate information about a static C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700356type StaticLibraryInfo struct {
357 StaticLibrary android.Path
358 Objects Objects
359 ReuseObjects Objects
360
Colin Crossa2bcf2c2022-02-11 13:11:55 -0800361 // A static library may contain prebuilt static libraries included with whole_static_libs
362 // that won't appear in Objects. They are transitively available in
363 // WholeStaticLibsFromPrebuilts.
364 WholeStaticLibsFromPrebuilts android.Paths
365
Colin Cross0de8a1e2020-09-18 14:15:30 -0700366 // This isn't the actual transitive DepSet, shared library dependencies have been
367 // converted into static library analogues. It is only used to order the static
368 // library dependencies that were specified for the current module.
369 TransitiveStaticLibrariesForOrdering *android.DepSet
370}
371
372var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
373
Colin Cross649d8172020-12-10 12:30:21 -0800374// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
375type HeaderLibraryInfo struct {
376}
377
378// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
379var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{})
380
Chris Parsons3c27ca32020-11-20 12:42:07 -0500381// FlagExporterInfo is a provider to propagate transitive library information
382// pertaining to exported include paths and flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700383type FlagExporterInfo struct {
Chris Parsons3c27ca32020-11-20 12:42:07 -0500384 IncludeDirs android.Paths // Include directories to be included with -I
385 SystemIncludeDirs android.Paths // System include directories to be included with -isystem
386 Flags []string // Exported raw flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700387 Deps android.Paths
388 GeneratedHeaders android.Paths
389}
390
391var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400392
393// flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
394func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
395
396 includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
397 systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
Liz Kammereb2d6d12021-12-06 14:56:25 -0500398 headers := android.PathsForBazelOut(ctx, ccInfo.Headers)
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400399
400 return FlagExporterInfo{
Chris Parsonsf60ecf02021-04-27 14:48:30 -0400401 IncludeDirs: android.FirstUniquePaths(includes),
402 SystemIncludeDirs: android.FirstUniquePaths(systemIncludes),
Liz Kammereb2d6d12021-12-06 14:56:25 -0500403 GeneratedHeaders: headers,
404 // necessary to ensure generated headers are considered implicit deps of dependent actions
405 Deps: headers,
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400406 }
407}