• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package cc
2
3import (
4	"android/soong/android"
5	"android/soong/fuzz"
6
7	"github.com/google/blueprint"
8	"github.com/google/blueprint/depset"
9)
10
11// 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
18	// 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	// SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
26	SetSanitizer(t SanitizerType, b bool)
27
28	// 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
40	// 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
54	// SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
55	SanitizableDepTagChecker() SantizableDependencyTagChecker
56
57	// ForceDisableSanitizers sets the ForceDisable sanitize property
58	ForceDisableSanitizers()
59}
60
61// SantizableDependencyTagChecker functions check whether or not a dependency
62// tag can be sanitized. These functions should return true if the tag can be
63// sanitized, otherwise they should return false. These functions should also
64// handle all possible dependency tags in the dependency tree. For example,
65// Rust modules can depend on both Rust and CC libraries, so the Rust module
66// implementation should handle tags from both.
67type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
68
69type VersionedLinkableInterface interface {
70	LinkableInterface
71	android.ApexModule
72
73	// VersionedInterface returns the VersionedInterface for this module
74	// (e.g. c.library), or nil if this is module is not a VersionedInterface.
75	VersionedInterface() VersionedInterface
76
77	// HasStubsVariants true if this module is a stub or has a sibling variant
78	// that is a stub.
79	HasStubsVariants() bool
80
81	// SetStl sets the stl property for CC modules. Does not panic if for other module types.
82	SetStl(string)
83	SetSdkVersion(string)
84	SetMinSdkVersion(version string)
85	ApexSdkVersion() android.ApiLevel
86	ImplementationModuleNameForMake() string
87
88	// RustApexExclude returns ApexExclude() for Rust modules; always returns false for all non-Rust modules.
89	// TODO(b/362509506): remove this once all apex_exclude uses are switched to stubs.
90	RustApexExclude() bool
91}
92
93// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
94type LinkableInterface interface {
95	android.Module
96
97	Module() android.Module
98	CcLibrary() bool
99	CcLibraryInterface() bool
100
101	// RustLibraryInterface returns true if this is a Rust library module
102	RustLibraryInterface() bool
103
104	// CrateName returns the crateName for a Rust library, panics if not a Rust library.
105	CrateName() string
106
107	// DepFlags returns a slice of Rustc string flags, panics if not a Rust library
108	ExportedCrateLinkDirs() []string
109
110	// BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
111	BaseModuleName() string
112
113	OutputFile() android.OptionalPath
114	UnstrippedOutputFile() android.Path
115	CoverageFiles() android.Paths
116
117	// CoverageOutputFile returns the output archive of gcno coverage information files.
118	CoverageOutputFile() android.OptionalPath
119
120	NonCcVariants() bool
121
122	SelectedStl() string
123
124	BuildStaticVariant() bool
125	BuildRlibVariant() bool
126	BuildSharedVariant() bool
127	SetStatic()
128	SetShared()
129	IsPrebuilt() bool
130	Toc() android.OptionalPath
131
132	// IsFuzzModule returns true if this a *_fuzz module.
133	IsFuzzModule() bool
134
135	// FuzzPackagedModule returns the fuzz.FuzzPackagedModule for this module.
136	// Expects that IsFuzzModule returns true.
137	FuzzPackagedModule() fuzz.FuzzPackagedModule
138
139	// FuzzSharedLibraries returns the shared library dependencies for this module.
140	// Expects that IsFuzzModule returns true.
141	FuzzSharedLibraries() android.RuleBuilderInstalls
142
143	Device() bool
144	Host() bool
145
146	InRamdisk() bool
147	OnlyInRamdisk() bool
148
149	InVendorRamdisk() bool
150	OnlyInVendorRamdisk() bool
151
152	InRecovery() bool
153	OnlyInRecovery() bool
154
155	InVendor() bool
156
157	UseSdk() bool
158
159	// IsNdk returns true if the library is in the configs known NDK list.
160	IsNdk(config android.Config) bool
161
162	// IsStubs returns true if the this is a stubs library.
163	IsStubs() bool
164
165	// IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
166	IsLlndk() bool
167
168	// NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
169	NeedsLlndkVariants() bool
170
171	// NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
172	NeedsVendorPublicLibraryVariants() bool
173
174	// UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
175	// "product" and "vendor" variant modules return true for this function.
176	// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
177	// "soc_specific: true" and more vendor installed modules are included here.
178	// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
179	// "product_specific: true" modules are included here.
180	UseVndk() bool
181
182	// Bootstrap tests if this module is allowed to use non-APEX version of libraries.
183	Bootstrap() bool
184
185	IsVendorPublicLibrary() bool
186	IsVndkPrebuiltLibrary() bool
187	HasVendorVariant() bool
188	HasProductVariant() bool
189	HasNonSystemVariants() bool
190	ProductSpecific() bool
191	InProduct() bool
192	SdkAndPlatformVariantVisibleToMake() bool
193	InVendorOrProduct() bool
194
195	// SubName returns the modules SubName, used for image and NDK/SDK variations.
196	SubName() string
197
198	SdkVersion() string
199	MinSdkVersion() string
200	AlwaysSdk() bool
201	IsSdkVariant() bool
202	Multilib() string
203
204	SplitPerApiLevel() bool
205
206	// SetPreventInstall sets the PreventInstall property to 'true' for this module.
207	SetPreventInstall()
208	// SetHideFromMake sets the HideFromMake property to 'true' for this module.
209	SetHideFromMake()
210
211	// KernelHeadersDecorator returns true if this is a kernel headers decorator module.
212	// This is specific to cc and should always return false for all other packages.
213	KernelHeadersDecorator() bool
214
215	// HiddenFromMake returns true if this module is hidden from Make.
216	HiddenFromMake() bool
217
218	// RelativeInstallPath returns the relative install path for this module.
219	RelativeInstallPath() string
220
221	// Binary returns true if this is a binary module.
222	Binary() bool
223
224	// Object returns true if this is an object module.
225	Object() bool
226
227	// Rlib returns true if this is an rlib module.
228	Rlib() bool
229
230	// Dylib returns true if this is an dylib module.
231	Dylib() bool
232
233	// RlibStd returns true if this is an rlib which links against an rlib libstd.
234	RlibStd() bool
235
236	// Static returns true if this is a static library module.
237	Static() bool
238
239	// Shared returns true if this is a shared library module.
240	Shared() bool
241
242	// Header returns true if this is a library headers module.
243	Header() bool
244
245	// StaticExecutable returns true if this is a binary module with "static_executable: true".
246	StaticExecutable() bool
247
248	// EverInstallable returns true if the module is ever installable
249	EverInstallable() bool
250
251	// PreventInstall returns true if this module is prevented from installation.
252	PreventInstall() bool
253
254	// InstallInData returns true if this module is installed in data.
255	InstallInData() bool
256
257	// Installable returns a bool pointer to the module installable property.
258	Installable() *bool
259
260	// Symlinks returns a list of symlinks that should be created for this module.
261	Symlinks() []string
262
263	// VndkVersion returns the VNDK version string for this module.
264	VndkVersion() string
265
266	// Partition returns the partition string for this module.
267	Partition() string
268
269	// FuzzModule returns the fuzz.FuzzModule associated with the module.
270	FuzzModuleStruct() fuzz.FuzzModule
271	IsCrt() bool
272}
273
274var (
275	// Dependency tag for crtbegin, an object file responsible for initialization.
276	CrtBeginDepTag = dependencyTag{name: "crtbegin"}
277	// Dependency tag for crtend, an object file responsible for program termination.
278	CrtEndDepTag = dependencyTag{name: "crtend"}
279	// Dependency tag for coverage library.
280	CoverageDepTag = dependencyTag{name: "coverage"}
281)
282
283// GetImageVariantType returns the ImageVariantType string value for the given module
284// (these are defined in cc/image.go).
285func GetImageVariantType(c LinkableInterface) ImageVariantType {
286	if c.Host() {
287		return hostImageVariant
288	} else if c.InVendor() {
289		return vendorImageVariant
290	} else if c.InProduct() {
291		return productImageVariant
292	} else if c.InRamdisk() {
293		return ramdiskImageVariant
294	} else if c.InVendorRamdisk() {
295		return vendorRamdiskImageVariant
296	} else if c.InRecovery() {
297		return recoveryImageVariant
298	} else {
299		return coreImageVariant
300	}
301}
302
303// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
304// Returns an empty string if not a library dependency tag.
305func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
306	if libDepTag, ok := depTag.(libraryDependencyTag); ok {
307		return libDepTag.makeSuffix
308	}
309	return ""
310}
311
312// SharedDepTag returns the dependency tag for any C++ shared libraries.
313func SharedDepTag() blueprint.DependencyTag {
314	return libraryDependencyTag{Kind: sharedLibraryDependency}
315}
316
317// StaticDepTag returns the dependency tag for any C++ static libraries.
318func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
319	return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
320}
321
322// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
323func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
324	if tag, ok := depTag.(libraryDependencyTag); ok {
325		return tag.wholeStatic
326	}
327	return false
328}
329
330// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
331func HeaderDepTag() blueprint.DependencyTag {
332	return libraryDependencyTag{Kind: headerLibraryDependency}
333}
334
335// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
336type SharedLibraryInfo struct {
337	SharedLibrary android.Path
338	Target        android.Target
339
340	TableOfContents    android.OptionalPath
341	IsStubs            bool
342	ImplementationDeps depset.DepSet[string]
343
344	// should be obtained from static analogue
345	TransitiveStaticLibrariesForOrdering depset.DepSet[android.Path]
346}
347
348var SharedLibraryInfoProvider = blueprint.NewProvider[SharedLibraryInfo]()
349
350// 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).
356	Version           string
357	SharedLibraryInfo SharedLibraryInfo
358	FlagExporterInfo  FlagExporterInfo
359}
360
361// 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
367
368	IsLLNDK bool
369}
370
371var SharedLibraryStubsProvider = blueprint.NewProvider[SharedLibraryStubsInfo]()
372
373// StaticLibraryInfo is a provider to propagate information about a static C++ library.
374type StaticLibraryInfo struct {
375	StaticLibrary android.Path
376	Objects       Objects
377	ReuseObjects  Objects
378
379	// 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
384	// 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 depset.DepSet[android.Path]
388}
389
390var StaticLibraryInfoProvider = blueprint.NewProvider[StaticLibraryInfo]()
391
392// 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
399// FlagExporterInfo is a provider to propagate transitive library information
400// pertaining to exported include paths and flags.
401type FlagExporterInfo struct {
402	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.
405	Deps              android.Paths
406	RustRlibDeps      []RustRlibDep
407	GeneratedHeaders  android.Paths
408}
409
410var FlagExporterInfoProvider = blueprint.NewProvider[FlagExporterInfo]()
411
412var ImplementationDepInfoProvider = blueprint.NewProvider[*ImplementationDepInfo]()
413
414type ImplementationDepInfo struct {
415	ImplementationDeps depset.DepSet[android.Path]
416}
417