• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package cc
2
3import (
4	"android/soong/android"
5	"android/soong/bazel/cquery"
6	"android/soong/snapshot"
7
8	"github.com/google/blueprint"
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	// 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
47	// 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
61	// 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
73// Snapshottable defines those functions necessary for handling module snapshots.
74type Snapshottable interface {
75	snapshot.VendorSnapshotModuleInterface
76	snapshot.RecoverySnapshotModuleInterface
77
78	// SnapshotHeaders returns a list of header paths provided by this module.
79	SnapshotHeaders() android.Paths
80
81	// SnapshotLibrary returns true if this module is a snapshot library.
82	IsSnapshotLibrary() bool
83
84	// EffectiveLicenseFiles returns the list of License files for this module.
85	EffectiveLicenseFiles() android.Paths
86
87	// 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
93	// SnapshotStaticLibs returns the list of static library dependencies for this module.
94	SnapshotStaticLibs() []string
95
96	// IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
97	IsSnapshotPrebuilt() bool
98}
99
100// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
101type LinkableInterface interface {
102	android.Module
103	Snapshottable
104
105	Module() android.Module
106	CcLibrary() bool
107	CcLibraryInterface() bool
108
109	// BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
110	BaseModuleName() string
111
112	OutputFile() android.OptionalPath
113	UnstrippedOutputFile() android.Path
114	CoverageFiles() android.Paths
115
116	NonCcVariants() bool
117
118	SelectedStl() string
119
120	BuildStaticVariant() bool
121	BuildSharedVariant() bool
122	SetStatic()
123	SetShared()
124	IsPrebuilt() bool
125	Toc() android.OptionalPath
126
127	Device() bool
128	Host() bool
129
130	InRamdisk() bool
131	OnlyInRamdisk() bool
132
133	InVendorRamdisk() bool
134	OnlyInVendorRamdisk() bool
135
136	InRecovery() bool
137	OnlyInRecovery() bool
138
139	InVendor() bool
140
141	UseSdk() bool
142
143	// IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
144	IsLlndk() bool
145
146	// IsLlndkPublic returns true only for LLNDK (public) libs.
147	IsLlndkPublic() bool
148
149	// HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
150	HasLlndkStubs() bool
151
152	// NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
153	NeedsLlndkVariants() bool
154
155	// NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
156	NeedsVendorPublicLibraryVariants() bool
157
158	//StubsVersion returns the stubs version for this module.
159	StubsVersion() string
160
161	// UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
162	// "product" and "vendor" variant modules return true for this function.
163	// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
164	// "soc_specific: true" and more vendor installed modules are included here.
165	// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
166	// "product_specific: true" modules are included here.
167	UseVndk() bool
168
169	// Bootstrap tests if this module is allowed to use non-APEX version of libraries.
170	Bootstrap() bool
171
172	// IsVndkSp returns true if this is a VNDK-SP module.
173	IsVndkSp() bool
174
175	MustUseVendorVariant() bool
176	IsVndk() bool
177	IsVndkExt() bool
178	IsVndkPrivate() bool
179	IsVendorPublicLibrary() bool
180	IsVndkPrebuiltLibrary() bool
181	HasVendorVariant() bool
182	HasProductVariant() bool
183	HasNonSystemVariants() bool
184	ProductSpecific() bool
185	InProduct() bool
186	SdkAndPlatformVariantVisibleToMake() bool
187
188	// SubName returns the modules SubName, used for image and NDK/SDK variations.
189	SubName() string
190
191	SdkVersion() string
192	MinSdkVersion() string
193	AlwaysSdk() bool
194	IsSdkVariant() bool
195
196	SplitPerApiLevel() bool
197
198	// SetPreventInstall sets the PreventInstall property to 'true' for this module.
199	SetPreventInstall()
200	// SetHideFromMake sets the HideFromMake property to 'true' for this module.
201	SetHideFromMake()
202
203	// KernelHeadersDecorator returns true if this is a kernel headers decorator module.
204	// This is specific to cc and should always return false for all other packages.
205	KernelHeadersDecorator() bool
206
207	// HiddenFromMake returns true if this module is hidden from Make.
208	HiddenFromMake() bool
209
210	// RelativeInstallPath returns the relative install path for this module.
211	RelativeInstallPath() string
212
213	// Binary returns true if this is a binary module.
214	Binary() bool
215
216	// Object returns true if this is an object module.
217	Object() bool
218
219	// Rlib returns true if this is an rlib module.
220	Rlib() bool
221
222	// Dylib returns true if this is an dylib module.
223	Dylib() bool
224
225	// Static returns true if this is a static library module.
226	Static() bool
227
228	// Shared returns true if this is a shared library module.
229	Shared() bool
230
231	// Header returns true if this is a library headers module.
232	Header() bool
233
234	// StaticExecutable returns true if this is a binary module with "static_executable: true".
235	StaticExecutable() bool
236
237	// EverInstallable returns true if the module is ever installable
238	EverInstallable() bool
239
240	// PreventInstall returns true if this module is prevented from installation.
241	PreventInstall() bool
242
243	// InstallInData returns true if this module is installed in data.
244	InstallInData() bool
245
246	// Installable returns a bool pointer to the module installable property.
247	Installable() *bool
248
249	// Symlinks returns a list of symlinks that should be created for this module.
250	Symlinks() []string
251
252	// VndkVersion returns the VNDK version string for this module.
253	VndkVersion() string
254}
255
256var (
257	// Dependency tag for crtbegin, an object file responsible for initialization.
258	CrtBeginDepTag = dependencyTag{name: "crtbegin"}
259	// Dependency tag for crtend, an object file responsible for program termination.
260	CrtEndDepTag = dependencyTag{name: "crtend"}
261	// Dependency tag for coverage library.
262	CoverageDepTag = dependencyTag{name: "coverage"}
263)
264
265// GetImageVariantType returns the ImageVariantType string value for the given module
266// (these are defined in cc/image.go).
267func GetImageVariantType(c LinkableInterface) ImageVariantType {
268	if c.Host() {
269		return hostImageVariant
270	} else if c.InVendor() {
271		return vendorImageVariant
272	} else if c.InProduct() {
273		return productImageVariant
274	} else if c.InRamdisk() {
275		return ramdiskImageVariant
276	} else if c.InVendorRamdisk() {
277		return vendorRamdiskImageVariant
278	} else if c.InRecovery() {
279		return recoveryImageVariant
280	} else {
281		return coreImageVariant
282	}
283}
284
285// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
286// Returns an empty string if not a library dependency tag.
287func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
288	if libDepTag, ok := depTag.(libraryDependencyTag); ok {
289		return libDepTag.makeSuffix
290	}
291	return ""
292}
293
294// SharedDepTag returns the dependency tag for any C++ shared libraries.
295func SharedDepTag() blueprint.DependencyTag {
296	return libraryDependencyTag{Kind: sharedLibraryDependency}
297}
298
299// StaticDepTag returns the dependency tag for any C++ static libraries.
300func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
301	return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
302}
303
304// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
305func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
306	if tag, ok := depTag.(libraryDependencyTag); ok {
307		return tag.wholeStatic
308	}
309	return false
310}
311
312// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
313func HeaderDepTag() blueprint.DependencyTag {
314	return libraryDependencyTag{Kind: headerLibraryDependency}
315}
316
317// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
318type SharedLibraryInfo struct {
319	SharedLibrary android.Path
320	Target        android.Target
321
322	TableOfContents android.OptionalPath
323
324	// should be obtained from static analogue
325	TransitiveStaticLibrariesForOrdering *android.DepSet
326}
327
328var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
329
330// SharedStubLibrary is a struct containing information about a stub shared library.
331// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
332// library in another APEX, it must depend on the stub version of that library.
333type SharedStubLibrary struct {
334	// The version of the stub (corresponding to the stable version of the shared library being
335	// stubbed).
336	Version           string
337	SharedLibraryInfo SharedLibraryInfo
338	FlagExporterInfo  FlagExporterInfo
339}
340
341// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
342// which are dependencies of a library.
343// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
344// library in another APEX, it must depend on the stub version of that library.
345type SharedLibraryStubsInfo struct {
346	SharedStubLibraries []SharedStubLibrary
347
348	IsLLNDK bool
349}
350
351var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{})
352
353// StaticLibraryInfo is a provider to propagate information about a static C++ library.
354type StaticLibraryInfo struct {
355	StaticLibrary android.Path
356	Objects       Objects
357	ReuseObjects  Objects
358
359	// A static library may contain prebuilt static libraries included with whole_static_libs
360	// that won't appear in Objects.  They are transitively available in
361	// WholeStaticLibsFromPrebuilts.
362	WholeStaticLibsFromPrebuilts android.Paths
363
364	// This isn't the actual transitive DepSet, shared library dependencies have been
365	// converted into static library analogues.  It is only used to order the static
366	// library dependencies that were specified for the current module.
367	TransitiveStaticLibrariesForOrdering *android.DepSet
368}
369
370var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
371
372// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
373type HeaderLibraryInfo struct {
374}
375
376// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
377var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{})
378
379// FlagExporterInfo is a provider to propagate transitive library information
380// pertaining to exported include paths and flags.
381type FlagExporterInfo struct {
382	IncludeDirs       android.Paths // Include directories to be included with -I
383	SystemIncludeDirs android.Paths // System include directories to be included with -isystem
384	Flags             []string      // Exported raw flags.
385	Deps              android.Paths
386	GeneratedHeaders  android.Paths
387}
388
389var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
390
391// flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
392func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
393
394	includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
395	systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
396	headers := android.PathsForBazelOut(ctx, ccInfo.Headers)
397
398	return FlagExporterInfo{
399		IncludeDirs:       android.FirstUniquePaths(includes),
400		SystemIncludeDirs: android.FirstUniquePaths(systemIncludes),
401		GeneratedHeaders:  headers,
402		// necessary to ensure generated headers are considered implicit deps of dependent actions
403		Deps: headers,
404	}
405}
406