1package cc
2
3import (
4	"android/soong/android"
5	"android/soong/fuzz"
6
7	"github.com/google/blueprint"
8)
9
10// 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
17	// 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	// SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
25	SetSanitizer(t SanitizerType, b bool)
26
27	// StaticallyLinked returns true if the module is statically linked.
28	StaticallyLinked() bool
29
30	// SetInSanitizerDir sets the module installation to the sanitizer directory.
31	SetInSanitizerDir()
32
33	// SanitizeNever returns true if this module should never be sanitized.
34	SanitizeNever() bool
35
36	// SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
37	SanitizerSupported(t SanitizerType) bool
38
39	// MinimalRuntimeDep returns true if this module needs to link the minimal UBSan runtime,
40	// either because it requires it or because a dependent module which requires it to be linked in this module.
41	MinimalRuntimeDep() bool
42
43	// UbsanRuntimeDep returns true if this module needs to link the full UBSan runtime,
44	// either because it requires it or because a dependent module which requires it to be linked in this module.
45	UbsanRuntimeDep() bool
46
47	// UbsanRuntimeNeeded returns true if the full UBSan runtime is required by this module.
48	UbsanRuntimeNeeded() bool
49
50	// MinimalRuntimeNeeded returns true if the minimal UBSan runtime is required by this module
51	MinimalRuntimeNeeded() bool
52
53	// SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
54	SanitizableDepTagChecker() SantizableDependencyTagChecker
55}
56
57// SantizableDependencyTagChecker functions check whether or not a dependency
58// tag can be sanitized. These functions should return true if the tag can be
59// sanitized, otherwise they should return false. These functions should also
60// handle all possible dependency tags in the dependency tree. For example,
61// Rust modules can depend on both Rust and CC libraries, so the Rust module
62// implementation should handle tags from both.
63type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
64
65// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
66type LinkableInterface interface {
67	android.Module
68
69	Module() android.Module
70	CcLibrary() bool
71	CcLibraryInterface() bool
72
73	// RustLibraryInterface returns true if this is a Rust library module
74	RustLibraryInterface() bool
75
76	// CrateName returns the crateName for a Rust library, panics if not a Rust library.
77	CrateName() string
78
79	// DepFlags returns a slice of Rustc string flags, panics if not a Rust library
80	ExportedCrateLinkDirs() []string
81
82	// BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
83	BaseModuleName() string
84
85	OutputFile() android.OptionalPath
86	UnstrippedOutputFile() android.Path
87	CoverageFiles() android.Paths
88
89	// CoverageOutputFile returns the output archive of gcno coverage information files.
90	CoverageOutputFile() android.OptionalPath
91
92	NonCcVariants() bool
93
94	SelectedStl() string
95
96	BuildStaticVariant() bool
97	BuildSharedVariant() bool
98	SetStatic()
99	SetShared()
100	IsPrebuilt() bool
101	Toc() android.OptionalPath
102
103	// IsFuzzModule returns true if this a *_fuzz module.
104	IsFuzzModule() bool
105
106	// FuzzPackagedModule returns the fuzz.FuzzPackagedModule for this module.
107	// Expects that IsFuzzModule returns true.
108	FuzzPackagedModule() fuzz.FuzzPackagedModule
109
110	// FuzzSharedLibraries returns the shared library dependencies for this module.
111	// Expects that IsFuzzModule returns true.
112	FuzzSharedLibraries() android.RuleBuilderInstalls
113
114	Device() bool
115	Host() bool
116
117	InRamdisk() bool
118	OnlyInRamdisk() bool
119
120	InVendorRamdisk() bool
121	OnlyInVendorRamdisk() bool
122
123	InRecovery() bool
124	OnlyInRecovery() bool
125
126	InVendor() bool
127
128	UseSdk() bool
129
130	// IsNdk returns true if the library is in the configs known NDK list.
131	IsNdk(config android.Config) bool
132
133	// IsStubs returns true if the this is a stubs library.
134	IsStubs() bool
135
136	// IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
137	IsLlndk() bool
138
139	// HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
140	HasLlndkStubs() bool
141
142	// NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
143	NeedsLlndkVariants() bool
144
145	// NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
146	NeedsVendorPublicLibraryVariants() bool
147
148	//StubsVersion returns the stubs version for this module.
149	StubsVersion() string
150
151	// UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
152	// "product" and "vendor" variant modules return true for this function.
153	// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
154	// "soc_specific: true" and more vendor installed modules are included here.
155	// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
156	// "product_specific: true" modules are included here.
157	UseVndk() bool
158
159	// Bootstrap tests if this module is allowed to use non-APEX version of libraries.
160	Bootstrap() bool
161
162	IsVendorPublicLibrary() bool
163	IsVndkPrebuiltLibrary() bool
164	HasVendorVariant() bool
165	HasProductVariant() bool
166	HasNonSystemVariants() bool
167	ProductSpecific() bool
168	InProduct() bool
169	SdkAndPlatformVariantVisibleToMake() bool
170	InVendorOrProduct() bool
171
172	// SubName returns the modules SubName, used for image and NDK/SDK variations.
173	SubName() string
174
175	SdkVersion() string
176	MinSdkVersion() string
177	AlwaysSdk() bool
178	IsSdkVariant() bool
179
180	SplitPerApiLevel() bool
181
182	// SetPreventInstall sets the PreventInstall property to 'true' for this module.
183	SetPreventInstall()
184	// SetHideFromMake sets the HideFromMake property to 'true' for this module.
185	SetHideFromMake()
186
187	// KernelHeadersDecorator returns true if this is a kernel headers decorator module.
188	// This is specific to cc and should always return false for all other packages.
189	KernelHeadersDecorator() bool
190
191	// HiddenFromMake returns true if this module is hidden from Make.
192	HiddenFromMake() bool
193
194	// RelativeInstallPath returns the relative install path for this module.
195	RelativeInstallPath() string
196
197	// Binary returns true if this is a binary module.
198	Binary() bool
199
200	// Object returns true if this is an object module.
201	Object() bool
202
203	// Rlib returns true if this is an rlib module.
204	Rlib() bool
205
206	// Dylib returns true if this is an dylib module.
207	Dylib() bool
208
209	// RlibStd returns true if this is an rlib which links against an rlib libstd.
210	RlibStd() bool
211
212	// Static returns true if this is a static library module.
213	Static() bool
214
215	// Shared returns true if this is a shared library module.
216	Shared() bool
217
218	// Header returns true if this is a library headers module.
219	Header() bool
220
221	// StaticExecutable returns true if this is a binary module with "static_executable: true".
222	StaticExecutable() bool
223
224	// EverInstallable returns true if the module is ever installable
225	EverInstallable() bool
226
227	// PreventInstall returns true if this module is prevented from installation.
228	PreventInstall() bool
229
230	// InstallInData returns true if this module is installed in data.
231	InstallInData() bool
232
233	// Installable returns a bool pointer to the module installable property.
234	Installable() *bool
235
236	// Symlinks returns a list of symlinks that should be created for this module.
237	Symlinks() []string
238
239	// VndkVersion returns the VNDK version string for this module.
240	VndkVersion() string
241
242	// Partition returns the partition string for this module.
243	Partition() string
244
245	// FuzzModule returns the fuzz.FuzzModule associated with the module.
246	FuzzModuleStruct() fuzz.FuzzModule
247}
248
249var (
250	// Dependency tag for crtbegin, an object file responsible for initialization.
251	CrtBeginDepTag = dependencyTag{name: "crtbegin"}
252	// Dependency tag for crtend, an object file responsible for program termination.
253	CrtEndDepTag = dependencyTag{name: "crtend"}
254	// Dependency tag for coverage library.
255	CoverageDepTag = dependencyTag{name: "coverage"}
256)
257
258// GetImageVariantType returns the ImageVariantType string value for the given module
259// (these are defined in cc/image.go).
260func GetImageVariantType(c LinkableInterface) ImageVariantType {
261	if c.Host() {
262		return hostImageVariant
263	} else if c.InVendor() {
264		return vendorImageVariant
265	} else if c.InProduct() {
266		return productImageVariant
267	} else if c.InRamdisk() {
268		return ramdiskImageVariant
269	} else if c.InVendorRamdisk() {
270		return vendorRamdiskImageVariant
271	} else if c.InRecovery() {
272		return recoveryImageVariant
273	} else {
274		return coreImageVariant
275	}
276}
277
278// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
279// Returns an empty string if not a library dependency tag.
280func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
281	if libDepTag, ok := depTag.(libraryDependencyTag); ok {
282		return libDepTag.makeSuffix
283	}
284	return ""
285}
286
287// SharedDepTag returns the dependency tag for any C++ shared libraries.
288func SharedDepTag() blueprint.DependencyTag {
289	return libraryDependencyTag{Kind: sharedLibraryDependency}
290}
291
292// StaticDepTag returns the dependency tag for any C++ static libraries.
293func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
294	return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
295}
296
297// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
298func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
299	if tag, ok := depTag.(libraryDependencyTag); ok {
300		return tag.wholeStatic
301	}
302	return false
303}
304
305// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
306func HeaderDepTag() blueprint.DependencyTag {
307	return libraryDependencyTag{Kind: headerLibraryDependency}
308}
309
310// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
311type SharedLibraryInfo struct {
312	SharedLibrary android.Path
313	Target        android.Target
314
315	TableOfContents android.OptionalPath
316
317	// should be obtained from static analogue
318	TransitiveStaticLibrariesForOrdering *android.DepSet[android.Path]
319}
320
321var SharedLibraryInfoProvider = blueprint.NewProvider[SharedLibraryInfo]()
322
323// SharedStubLibrary is a struct containing information about a stub shared library.
324// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
325// library in another APEX, it must depend on the stub version of that library.
326type SharedStubLibrary struct {
327	// The version of the stub (corresponding to the stable version of the shared library being
328	// stubbed).
329	Version           string
330	SharedLibraryInfo SharedLibraryInfo
331	FlagExporterInfo  FlagExporterInfo
332}
333
334// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
335// which are dependencies of a library.
336// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
337// library in another APEX, it must depend on the stub version of that library.
338type SharedLibraryStubsInfo struct {
339	SharedStubLibraries []SharedStubLibrary
340
341	IsLLNDK bool
342}
343
344var SharedLibraryStubsProvider = blueprint.NewProvider[SharedLibraryStubsInfo]()
345
346// StaticLibraryInfo is a provider to propagate information about a static C++ library.
347type StaticLibraryInfo struct {
348	StaticLibrary android.Path
349	Objects       Objects
350	ReuseObjects  Objects
351
352	// A static library may contain prebuilt static libraries included with whole_static_libs
353	// that won't appear in Objects.  They are transitively available in
354	// WholeStaticLibsFromPrebuilts.
355	WholeStaticLibsFromPrebuilts android.Paths
356
357	// This isn't the actual transitive DepSet, shared library dependencies have been
358	// converted into static library analogues.  It is only used to order the static
359	// library dependencies that were specified for the current module.
360	TransitiveStaticLibrariesForOrdering *android.DepSet[android.Path]
361}
362
363var StaticLibraryInfoProvider = blueprint.NewProvider[StaticLibraryInfo]()
364
365// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
366type HeaderLibraryInfo struct {
367}
368
369// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
370var HeaderLibraryInfoProvider = blueprint.NewProvider[HeaderLibraryInfo]()
371
372// FlagExporterInfo is a provider to propagate transitive library information
373// pertaining to exported include paths and flags.
374type FlagExporterInfo struct {
375	IncludeDirs       android.Paths // Include directories to be included with -I
376	SystemIncludeDirs android.Paths // System include directories to be included with -isystem
377	Flags             []string      // Exported raw flags.
378	Deps              android.Paths
379	RustRlibDeps      []RustRlibDep
380	GeneratedHeaders  android.Paths
381}
382
383var FlagExporterInfoProvider = blueprint.NewProvider[FlagExporterInfo]()
384