• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package cc
2
3import (
4	"android/soong/android"
5	"android/soong/bazel/cquery"
6	"android/soong/fuzz"
7	"android/soong/snapshot"
8
9	"github.com/google/blueprint"
10)
11
12// 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
19	// 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
26	// SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
27	SetSanitizer(t SanitizerType, b bool)
28
29	// 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
41	// 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
55	// 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
67// Snapshottable defines those functions necessary for handling module snapshots.
68type Snapshottable interface {
69	snapshot.VendorSnapshotModuleInterface
70	snapshot.RecoverySnapshotModuleInterface
71
72	// SnapshotHeaders returns a list of header paths provided by this module.
73	SnapshotHeaders() android.Paths
74
75	// SnapshotLibrary returns true if this module is a snapshot library.
76	IsSnapshotLibrary() bool
77
78	// EffectiveLicenseFiles returns the list of License files for this module.
79	EffectiveLicenseFiles() android.Paths
80
81	// 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
87	// SnapshotStaticLibs returns the list of static library dependencies for this module.
88	SnapshotStaticLibs() []string
89
90	// IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
91	IsSnapshotPrebuilt() bool
92}
93
94// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
95type LinkableInterface interface {
96	android.Module
97	Snapshottable
98
99	Module() android.Module
100	CcLibrary() bool
101	CcLibraryInterface() bool
102
103	// BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
104	BaseModuleName() string
105
106	OutputFile() android.OptionalPath
107	UnstrippedOutputFile() android.Path
108	CoverageFiles() android.Paths
109
110	// CoverageOutputFile returns the output archive of gcno coverage information files.
111	CoverageOutputFile() android.OptionalPath
112
113	NonCcVariants() bool
114
115	SelectedStl() string
116
117	BuildStaticVariant() bool
118	BuildSharedVariant() bool
119	SetStatic()
120	SetShared()
121	IsPrebuilt() bool
122	Toc() android.OptionalPath
123
124	// 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.
133	FuzzSharedLibraries() android.Paths
134
135	Device() bool
136	Host() bool
137
138	InRamdisk() bool
139	OnlyInRamdisk() bool
140
141	InVendorRamdisk() bool
142	OnlyInVendorRamdisk() bool
143
144	InRecovery() bool
145	OnlyInRecovery() bool
146
147	InVendor() bool
148
149	UseSdk() bool
150
151	// 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
157	// 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
163	// HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
164	HasLlndkStubs() bool
165
166	// NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
167	NeedsLlndkVariants() bool
168
169	// NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
170	NeedsVendorPublicLibraryVariants() bool
171
172	//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.
181	UseVndk() bool
182
183	// Bootstrap tests if this module is allowed to use non-APEX version of libraries.
184	Bootstrap() bool
185
186	// IsVndkSp returns true if this is a VNDK-SP module.
187	IsVndkSp() bool
188
189	MustUseVendorVariant() bool
190	IsVndk() bool
191	IsVndkExt() bool
192	IsVndkPrivate() bool
193	IsVendorPublicLibrary() bool
194	IsVndkPrebuiltLibrary() bool
195	HasVendorVariant() bool
196	HasProductVariant() bool
197	HasNonSystemVariants() bool
198	ProductSpecific() bool
199	InProduct() bool
200	SdkAndPlatformVariantVisibleToMake() bool
201
202	// SubName returns the modules SubName, used for image and NDK/SDK variations.
203	SubName() string
204
205	SdkVersion() string
206	MinSdkVersion() string
207	AlwaysSdk() bool
208	IsSdkVariant() bool
209
210	SplitPerApiLevel() bool
211
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()
216
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
220
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
248	// StaticExecutable returns true if this is a binary module with "static_executable: true".
249	StaticExecutable() bool
250
251	// 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
268
269	// Partition returns the partition string for this module.
270	Partition() string
271
272	// FuzzModule returns the fuzz.FuzzModule associated with the module.
273	FuzzModuleStruct() fuzz.FuzzModule
274}
275
276var (
277	// Dependency tag for crtbegin, an object file responsible for initialization.
278	CrtBeginDepTag = dependencyTag{name: "crtbegin"}
279	// Dependency tag for crtend, an object file responsible for program termination.
280	CrtEndDepTag = dependencyTag{name: "crtend"}
281	// Dependency tag for coverage library.
282	CoverageDepTag = dependencyTag{name: "coverage"}
283)
284
285// 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
305// 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
314// SharedDepTag returns the dependency tag for any C++ shared libraries.
315func SharedDepTag() blueprint.DependencyTag {
316	return libraryDependencyTag{Kind: sharedLibraryDependency}
317}
318
319// StaticDepTag returns the dependency tag for any C++ static libraries.
320func 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
330}
331
332// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
333func HeaderDepTag() blueprint.DependencyTag {
334	return libraryDependencyTag{Kind: headerLibraryDependency}
335}
336
337// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
338type SharedLibraryInfo struct {
339	SharedLibrary android.Path
340	Target        android.Target
341
342	TableOfContents android.OptionalPath
343
344	// should be obtained from static analogue
345	TransitiveStaticLibrariesForOrdering *android.DepSet
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 *android.DepSet
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	GeneratedHeaders  android.Paths
407}
408
409var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
410
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)
416	headers := android.PathsForBazelOut(ctx, ccInfo.Headers)
417
418	return FlagExporterInfo{
419		IncludeDirs:       android.FirstUniquePaths(includes),
420		SystemIncludeDirs: android.FirstUniquePaths(systemIncludes),
421		GeneratedHeaders:  headers,
422		// necessary to ensure generated headers are considered implicit deps of dependent actions
423		Deps: headers,
424	}
425}
426