blob: bad4b4ab940151a817476859b52648d5fb24f01c [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
25 // SanitizeDep returns the value of the SanitizeDep flag, which is set if a module is a dependency of a
26 // sanitized module.
27 SanitizeDep() bool
28
29 // SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
30 SetSanitizer(t SanitizerType, b bool)
31
32 // SetSanitizerDep returns true if the module is statically linked.
33 SetSanitizeDep(b bool)
34
35 // StaticallyLinked returns true if the module is statically linked.
36 StaticallyLinked() bool
37
38 // SetInSanitizerDir sets the module installation to the sanitizer directory.
39 SetInSanitizerDir()
40
41 // SanitizeNever returns true if this module should never be sanitized.
42 SanitizeNever() bool
43
44 // SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
45 SanitizerSupported(t SanitizerType) bool
46
Ivan Lozanod7586b62021-04-01 09:49:36 -040047 // MinimalRuntimeDep returns true if this module needs to link the minimal UBSan runtime,
48 // either because it requires it or because a dependent module which requires it to be linked in this module.
49 MinimalRuntimeDep() bool
50
51 // UbsanRuntimeDep returns true if this module needs to link the full UBSan runtime,
52 // either because it requires it or because a dependent module which requires it to be linked in this module.
53 UbsanRuntimeDep() bool
54
55 // UbsanRuntimeNeeded returns true if the full UBSan runtime is required by this module.
56 UbsanRuntimeNeeded() bool
57
58 // MinimalRuntimeNeeded returns true if the minimal UBSan runtime is required by this module
59 MinimalRuntimeNeeded() bool
60
Ivan Lozano3968d8f2020-12-14 11:27:52 -050061 // SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
62 SanitizableDepTagChecker() SantizableDependencyTagChecker
63}
64
65// SantizableDependencyTagChecker functions check whether or not a dependency
66// tag can be sanitized. These functions should return true if the tag can be
67// sanitized, otherwise they should return false. These functions should also
68// handle all possible dependency tags in the dependency tree. For example,
69// Rust modules can depend on both Rust and CC libraries, so the Rust module
70// implementation should handle tags from both.
71type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
72
Ivan Lozanod7586b62021-04-01 09:49:36 -040073// Snapshottable defines those functions necessary for handling module snapshots.
74type Snapshottable interface {
Kiyoung Kim48f37782021-07-07 12:42:39 +090075 snapshot.VendorSnapshotModuleInterface
76 snapshot.RecoverySnapshotModuleInterface
77
Ivan Lozanod7586b62021-04-01 09:49:36 -040078 // SnapshotHeaders returns a list of header paths provided by this module.
79 SnapshotHeaders() android.Paths
80
Ivan Lozanod7586b62021-04-01 09:49:36 -040081 // SnapshotLibrary returns true if this module is a snapshot library.
82 IsSnapshotLibrary() bool
83
Justin Yun885a7de2021-06-29 20:34:53 +090084 // EffectiveLicenseFiles returns the list of License files for this module.
85 EffectiveLicenseFiles() android.Paths
86
Ivan Lozanod7586b62021-04-01 09:49:36 -040087 // SnapshotRuntimeLibs returns a list of libraries needed by this module at runtime but which aren't build dependencies.
88 SnapshotRuntimeLibs() []string
89
90 // SnapshotSharedLibs returns the list of shared library dependencies for this module.
91 SnapshotSharedLibs() []string
92
Justin Yun5e035862021-06-29 20:50:37 +090093 // SnapshotStaticLibs returns the list of static library dependencies for this module.
94 SnapshotStaticLibs() []string
95
Ivan Lozanod7586b62021-04-01 09:49:36 -040096 // IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
97 IsSnapshotPrebuilt() bool
98}
99
Chris Parsons3c27ca32020-11-20 12:42:07 -0500100// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
Ivan Lozano183a3212019-10-18 14:18:45 -0700101type LinkableInterface interface {
Ivan Lozanof9e21722020-12-02 09:00:51 -0500102 android.Module
Ivan Lozanod7586b62021-04-01 09:49:36 -0400103 Snapshottable
Ivan Lozanof9e21722020-12-02 09:00:51 -0500104
Ivan Lozano183a3212019-10-18 14:18:45 -0700105 Module() android.Module
106 CcLibrary() bool
107 CcLibraryInterface() bool
108
Ivan Lozanod7586b62021-04-01 09:49:36 -0400109 // BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
110 BaseModuleName() string
111
Ivan Lozano183a3212019-10-18 14:18:45 -0700112 OutputFile() android.OptionalPath
Ivan Lozano39b0bf02021-10-14 12:22:09 -0400113 UnstrippedOutputFile() android.Path
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400114 CoverageFiles() android.Paths
Ivan Lozano183a3212019-10-18 14:18:45 -0700115
Ivan Lozanobe6873f2022-06-27 16:00:26 -0400116 // CoverageOutputFile returns the output archive of gcno coverage information files.
117 CoverageOutputFile() android.OptionalPath
118
Ivan Lozano2b262972019-11-21 12:30:50 -0800119 NonCcVariants() bool
120
Ivan Lozano52767be2019-10-18 14:49:46 -0700121 SelectedStl() string
Ivan Lozano183a3212019-10-18 14:18:45 -0700122
123 BuildStaticVariant() bool
124 BuildSharedVariant() bool
125 SetStatic()
126 SetShared()
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500127 IsPrebuilt() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700128 Toc() android.OptionalPath
129
Yi-Yo Chiang36d8e4e2021-07-02 21:21:13 +0800130 Device() bool
Jooyung Han624d35c2020-04-10 12:57:24 +0900131 Host() bool
132
Yifan Hong1b3348d2020-01-21 15:53:22 -0800133 InRamdisk() bool
134 OnlyInRamdisk() bool
135
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700136 InVendorRamdisk() bool
137 OnlyInVendorRamdisk() bool
138
Ivan Lozano52767be2019-10-18 14:49:46 -0700139 InRecovery() bool
140 OnlyInRecovery() bool
141
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500142 InVendor() bool
143
Colin Crossc511bc52020-04-07 16:50:32 +0000144 UseSdk() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400145
Ivan Lozanobe6873f2022-06-27 16:00:26 -0400146 // IsNdk returns true if the library is in the configs known NDK list.
147 IsNdk(config android.Config) bool
148
149 // IsStubs returns true if the this is a stubs library.
150 IsStubs() bool
151
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400152 // IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
153 IsLlndk() bool
154
155 // IsLlndkPublic returns true only for LLNDK (public) libs.
156 IsLlndkPublic() bool
157
Ivan Lozanod7586b62021-04-01 09:49:36 -0400158 // HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
159 HasLlndkStubs() bool
160
Colin Cross1f3f1302021-04-26 18:37:44 -0700161 // NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
162 NeedsLlndkVariants() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400163
Colin Cross5271fea2021-04-27 13:06:04 -0700164 // NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
165 NeedsVendorPublicLibraryVariants() bool
166
Ivan Lozanod7586b62021-04-01 09:49:36 -0400167 //StubsVersion returns the stubs version for this module.
168 StubsVersion() string
169
170 // UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
171 // "product" and "vendor" variant modules return true for this function.
172 // When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
173 // "soc_specific: true" and more vendor installed modules are included here.
174 // When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
175 // "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700176 UseVndk() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400177
Jiyong Park7d55b612021-06-11 17:22:09 +0900178 // Bootstrap tests if this module is allowed to use non-APEX version of libraries.
179 Bootstrap() bool
180
Ivan Lozanod7586b62021-04-01 09:49:36 -0400181 // IsVndkSp returns true if this is a VNDK-SP module.
182 IsVndkSp() bool
183
Ivan Lozano52767be2019-10-18 14:49:46 -0700184 MustUseVendorVariant() bool
185 IsVndk() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500186 IsVndkExt() bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800187 IsVndkPrivate() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400188 IsVendorPublicLibrary() bool
189 IsVndkPrebuiltLibrary() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700190 HasVendorVariant() bool
Justin Yuncbca3732021-02-03 19:24:13 +0900191 HasProductVariant() bool
192 HasNonSystemVariants() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400193 ProductSpecific() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500194 InProduct() bool
Ivan Lozanof1868af2022-04-12 13:08:36 -0400195 SdkAndPlatformVariantVisibleToMake() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700196
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400197 // SubName returns the modules SubName, used for image and NDK/SDK variations.
198 SubName() string
199
Ivan Lozano52767be2019-10-18 14:49:46 -0700200 SdkVersion() string
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900201 MinSdkVersion() string
Colin Crossc511bc52020-04-07 16:50:32 +0000202 AlwaysSdk() bool
Jiyong Park2286afd2020-06-16 21:58:53 +0900203 IsSdkVariant() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700204
Colin Cross1348ce32020-10-01 13:37:16 -0700205 SplitPerApiLevel() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500206
207 // SetPreventInstall sets the PreventInstall property to 'true' for this module.
208 SetPreventInstall()
209 // SetHideFromMake sets the HideFromMake property to 'true' for this module.
210 SetHideFromMake()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400211
212 // KernelHeadersDecorator returns true if this is a kernel headers decorator module.
213 // This is specific to cc and should always return false for all other packages.
214 KernelHeadersDecorator() bool
Ivan Lozanod7586b62021-04-01 09:49:36 -0400215
216 // HiddenFromMake returns true if this module is hidden from Make.
217 HiddenFromMake() bool
218
219 // RelativeInstallPath returns the relative install path for this module.
220 RelativeInstallPath() string
221
222 // Binary returns true if this is a binary module.
223 Binary() bool
224
225 // Object returns true if this is an object module.
226 Object() bool
227
228 // Rlib returns true if this is an rlib module.
229 Rlib() bool
230
231 // Dylib returns true if this is an dylib module.
232 Dylib() bool
233
234 // Static returns true if this is a static library module.
235 Static() bool
236
237 // Shared returns true if this is a shared library module.
238 Shared() bool
239
240 // Header returns true if this is a library headers module.
241 Header() bool
242
Justin Yun5e035862021-06-29 20:50:37 +0900243 // StaticExecutable returns true if this is a binary module with "static_executable: true".
244 StaticExecutable() bool
245
Ivan Lozanod7586b62021-04-01 09:49:36 -0400246 // EverInstallable returns true if the module is ever installable
247 EverInstallable() bool
248
249 // PreventInstall returns true if this module is prevented from installation.
250 PreventInstall() bool
251
252 // InstallInData returns true if this module is installed in data.
253 InstallInData() bool
254
255 // Installable returns a bool pointer to the module installable property.
256 Installable() *bool
257
258 // Symlinks returns a list of symlinks that should be created for this module.
259 Symlinks() []string
260
261 // VndkVersion returns the VNDK version string for this module.
262 VndkVersion() string
Ivan Lozano183a3212019-10-18 14:18:45 -0700263}
264
Colin Cross6e511a92020-07-27 21:26:48 -0700265var (
Chris Parsons3c27ca32020-11-20 12:42:07 -0500266 // Dependency tag for crtbegin, an object file responsible for initialization.
Colin Cross6e511a92020-07-27 21:26:48 -0700267 CrtBeginDepTag = dependencyTag{name: "crtbegin"}
Chris Parsons3c27ca32020-11-20 12:42:07 -0500268 // Dependency tag for crtend, an object file responsible for program termination.
269 CrtEndDepTag = dependencyTag{name: "crtend"}
270 // Dependency tag for coverage library.
Colin Cross6e511a92020-07-27 21:26:48 -0700271 CoverageDepTag = dependencyTag{name: "coverage"}
272)
Ivan Lozano183a3212019-10-18 14:18:45 -0700273
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500274// GetImageVariantType returns the ImageVariantType string value for the given module
275// (these are defined in cc/image.go).
276func GetImageVariantType(c LinkableInterface) ImageVariantType {
277 if c.Host() {
278 return hostImageVariant
279 } else if c.InVendor() {
280 return vendorImageVariant
281 } else if c.InProduct() {
282 return productImageVariant
283 } else if c.InRamdisk() {
284 return ramdiskImageVariant
285 } else if c.InVendorRamdisk() {
286 return vendorRamdiskImageVariant
287 } else if c.InRecovery() {
288 return recoveryImageVariant
289 } else {
290 return coreImageVariant
291 }
292}
293
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400294// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
295// Returns an empty string if not a library dependency tag.
296func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
297 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
298 return libDepTag.makeSuffix
299 }
300 return ""
301}
302
Chris Parsons3c27ca32020-11-20 12:42:07 -0500303// SharedDepTag returns the dependency tag for any C++ shared libraries.
Colin Cross6e511a92020-07-27 21:26:48 -0700304func SharedDepTag() blueprint.DependencyTag {
305 return libraryDependencyTag{Kind: sharedLibraryDependency}
Ivan Lozano183a3212019-10-18 14:18:45 -0700306}
307
Chris Parsons3c27ca32020-11-20 12:42:07 -0500308// StaticDepTag returns the dependency tag for any C++ static libraries.
Ivan Lozano63bb7682021-03-23 15:53:44 -0400309func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
310 return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
311}
312
313// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
314func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
315 if tag, ok := depTag.(libraryDependencyTag); ok {
316 return tag.wholeStatic
317 }
318 return false
Colin Cross6e511a92020-07-27 21:26:48 -0700319}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700320
Chris Parsons3c27ca32020-11-20 12:42:07 -0500321// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
Zach Johnson3df4e632020-11-06 11:56:27 -0800322func HeaderDepTag() blueprint.DependencyTag {
323 return libraryDependencyTag{Kind: headerLibraryDependency}
324}
325
Chris Parsons3c27ca32020-11-20 12:42:07 -0500326// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700327type SharedLibraryInfo struct {
Liz Kammeref6dfea2021-06-08 15:37:09 -0400328 SharedLibrary android.Path
329 Target android.Target
Colin Cross0de8a1e2020-09-18 14:15:30 -0700330
Liz Kammeref6dfea2021-06-08 15:37:09 -0400331 TableOfContents android.OptionalPath
Colin Cross0de8a1e2020-09-18 14:15:30 -0700332
Liz Kammeref6dfea2021-06-08 15:37:09 -0400333 // should be obtained from static analogue
334 TransitiveStaticLibrariesForOrdering *android.DepSet
Colin Cross0de8a1e2020-09-18 14:15:30 -0700335}
336
337var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
338
Chris Parsons3c27ca32020-11-20 12:42:07 -0500339// SharedStubLibrary is a struct containing information about a stub shared library.
340// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
341// library in another APEX, it must depend on the stub version of that library.
342type SharedStubLibrary struct {
343 // The version of the stub (corresponding to the stable version of the shared library being
344 // stubbed).
Colin Cross0de8a1e2020-09-18 14:15:30 -0700345 Version string
346 SharedLibraryInfo SharedLibraryInfo
347 FlagExporterInfo FlagExporterInfo
348}
349
Chris Parsons3c27ca32020-11-20 12:42:07 -0500350// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
351// which are dependencies of a library.
352// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
353// library in another APEX, it must depend on the stub version of that library.
354type SharedLibraryStubsInfo struct {
355 SharedStubLibraries []SharedStubLibrary
Colin Cross0de8a1e2020-09-18 14:15:30 -0700356
Chris Parsons3c27ca32020-11-20 12:42:07 -0500357 IsLLNDK bool
358}
359
360var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{})
361
362// StaticLibraryInfo is a provider to propagate information about a static C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700363type StaticLibraryInfo struct {
364 StaticLibrary android.Path
365 Objects Objects
366 ReuseObjects Objects
367
Colin Crossa2bcf2c2022-02-11 13:11:55 -0800368 // A static library may contain prebuilt static libraries included with whole_static_libs
369 // that won't appear in Objects. They are transitively available in
370 // WholeStaticLibsFromPrebuilts.
371 WholeStaticLibsFromPrebuilts android.Paths
372
Colin Cross0de8a1e2020-09-18 14:15:30 -0700373 // This isn't the actual transitive DepSet, shared library dependencies have been
374 // converted into static library analogues. It is only used to order the static
375 // library dependencies that were specified for the current module.
376 TransitiveStaticLibrariesForOrdering *android.DepSet
377}
378
379var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
380
Colin Cross649d8172020-12-10 12:30:21 -0800381// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
382type HeaderLibraryInfo struct {
383}
384
385// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
386var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{})
387
Chris Parsons3c27ca32020-11-20 12:42:07 -0500388// FlagExporterInfo is a provider to propagate transitive library information
389// pertaining to exported include paths and flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700390type FlagExporterInfo struct {
Chris Parsons3c27ca32020-11-20 12:42:07 -0500391 IncludeDirs android.Paths // Include directories to be included with -I
392 SystemIncludeDirs android.Paths // System include directories to be included with -isystem
393 Flags []string // Exported raw flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700394 Deps android.Paths
395 GeneratedHeaders android.Paths
396}
397
398var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400399
400// flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
401func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
402
403 includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
404 systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
Liz Kammereb2d6d12021-12-06 14:56:25 -0500405 headers := android.PathsForBazelOut(ctx, ccInfo.Headers)
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400406
407 return FlagExporterInfo{
Chris Parsonsf60ecf02021-04-27 14:48:30 -0400408 IncludeDirs: android.FirstUniquePaths(includes),
409 SystemIncludeDirs: android.FirstUniquePaths(systemIncludes),
Liz Kammereb2d6d12021-12-06 14:56:25 -0500410 GeneratedHeaders: headers,
411 // necessary to ensure generated headers are considered implicit deps of dependent actions
412 Deps: headers,
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400413 }
414}