blob: 8fe0b4a9df8dcbf57d0953b8ad3db1507afe4239 [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"
Colin Cross6e511a92020-07-27 21:26:48 -07006
7 "github.com/google/blueprint"
Ivan Lozano183a3212019-10-18 14:18:45 -07008)
9
Ivan Lozano3968d8f2020-12-14 11:27:52 -050010// 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 // IsDependencyRoot returns whether a module is of a type which cannot be a linkage dependency
18 // of another module. For example, cc_binary and rust_binary represent dependency roots as other
19 // modules cannot have linkage dependencies against these types.
20 IsDependencyRoot() bool
21
22 // IsSanitizerEnabled returns whether a sanitizer is enabled.
23 IsSanitizerEnabled(t SanitizerType) bool
24
25 // IsSanitizerExplicitlyDisabled returns whether a sanitizer has been explicitly disabled (set to false) rather
26 // than left undefined.
27 IsSanitizerExplicitlyDisabled(t SanitizerType) bool
28
29 // SanitizeDep returns the value of the SanitizeDep flag, which is set if a module is a dependency of a
30 // sanitized module.
31 SanitizeDep() bool
32
33 // SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
34 SetSanitizer(t SanitizerType, b bool)
35
36 // SetSanitizerDep returns true if the module is statically linked.
37 SetSanitizeDep(b bool)
38
39 // StaticallyLinked returns true if the module is statically linked.
40 StaticallyLinked() bool
41
42 // SetInSanitizerDir sets the module installation to the sanitizer directory.
43 SetInSanitizerDir()
44
45 // SanitizeNever returns true if this module should never be sanitized.
46 SanitizeNever() bool
47
48 // SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
49 SanitizerSupported(t SanitizerType) bool
50
51 // SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
52 SanitizableDepTagChecker() SantizableDependencyTagChecker
53}
54
55// SantizableDependencyTagChecker functions check whether or not a dependency
56// tag can be sanitized. These functions should return true if the tag can be
57// sanitized, otherwise they should return false. These functions should also
58// handle all possible dependency tags in the dependency tree. For example,
59// Rust modules can depend on both Rust and CC libraries, so the Rust module
60// implementation should handle tags from both.
61type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
62
Chris Parsons3c27ca32020-11-20 12:42:07 -050063// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
Ivan Lozano183a3212019-10-18 14:18:45 -070064type LinkableInterface interface {
Ivan Lozanof9e21722020-12-02 09:00:51 -050065 android.Module
66
Ivan Lozano183a3212019-10-18 14:18:45 -070067 Module() android.Module
68 CcLibrary() bool
69 CcLibraryInterface() bool
70
Ivan Lozano183a3212019-10-18 14:18:45 -070071 OutputFile() android.OptionalPath
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040072 CoverageFiles() android.Paths
Ivan Lozano183a3212019-10-18 14:18:45 -070073
Ivan Lozano2b262972019-11-21 12:30:50 -080074 NonCcVariants() bool
75
Ivan Lozano52767be2019-10-18 14:49:46 -070076 SelectedStl() string
Ivan Lozano183a3212019-10-18 14:18:45 -070077
78 BuildStaticVariant() bool
79 BuildSharedVariant() bool
80 SetStatic()
81 SetShared()
Ivan Lozano52767be2019-10-18 14:49:46 -070082 Static() bool
83 Shared() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -050084 Header() bool
85 IsPrebuilt() bool
Ivan Lozano52767be2019-10-18 14:49:46 -070086 Toc() android.OptionalPath
87
Jooyung Han624d35c2020-04-10 12:57:24 +090088 Host() bool
89
Yifan Hong1b3348d2020-01-21 15:53:22 -080090 InRamdisk() bool
91 OnlyInRamdisk() bool
92
Yifan Hong60e0cfb2020-10-21 15:17:56 -070093 InVendorRamdisk() bool
94 OnlyInVendorRamdisk() bool
95
Ivan Lozano52767be2019-10-18 14:49:46 -070096 InRecovery() bool
97 OnlyInRecovery() bool
98
Ivan Lozano3968d8f2020-12-14 11:27:52 -050099 InVendor() bool
100
Colin Crossc511bc52020-04-07 16:50:32 +0000101 UseSdk() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400102
103 // IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
104 IsLlndk() bool
105
106 // IsLlndkPublic returns true only for LLNDK (public) libs.
107 IsLlndkPublic() bool
108
109 // IsLlndkHeaders returns true if this module is an LLNDK headers module.
110 IsLlndkHeaders() bool
111
112 // IsLlndkLibrary returns true if this module is an LLNDK library module.
113 IsLlndkLibrary() bool
114
Colin Cross1f3f1302021-04-26 18:37:44 -0700115 // NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
116 NeedsLlndkVariants() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400117
Ivan Lozano52767be2019-10-18 14:49:46 -0700118 UseVndk() bool
119 MustUseVendorVariant() bool
120 IsVndk() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500121 IsVndkExt() bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800122 IsVndkPrivate() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700123 HasVendorVariant() bool
Justin Yuncbca3732021-02-03 19:24:13 +0900124 HasProductVariant() bool
125 HasNonSystemVariants() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500126 InProduct() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700127
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400128 // SubName returns the modules SubName, used for image and NDK/SDK variations.
129 SubName() string
130
Ivan Lozano52767be2019-10-18 14:49:46 -0700131 SdkVersion() string
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900132 MinSdkVersion() string
Colin Crossc511bc52020-04-07 16:50:32 +0000133 AlwaysSdk() bool
Jiyong Park2286afd2020-06-16 21:58:53 +0900134 IsSdkVariant() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700135
Colin Cross1348ce32020-10-01 13:37:16 -0700136 SplitPerApiLevel() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500137
138 // SetPreventInstall sets the PreventInstall property to 'true' for this module.
139 SetPreventInstall()
140 // SetHideFromMake sets the HideFromMake property to 'true' for this module.
141 SetHideFromMake()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400142
143 // KernelHeadersDecorator returns true if this is a kernel headers decorator module.
144 // This is specific to cc and should always return false for all other packages.
145 KernelHeadersDecorator() bool
Ivan Lozano183a3212019-10-18 14:18:45 -0700146}
147
Colin Cross6e511a92020-07-27 21:26:48 -0700148var (
Chris Parsons3c27ca32020-11-20 12:42:07 -0500149 // Dependency tag for crtbegin, an object file responsible for initialization.
Colin Cross6e511a92020-07-27 21:26:48 -0700150 CrtBeginDepTag = dependencyTag{name: "crtbegin"}
Chris Parsons3c27ca32020-11-20 12:42:07 -0500151 // Dependency tag for crtend, an object file responsible for program termination.
152 CrtEndDepTag = dependencyTag{name: "crtend"}
153 // Dependency tag for coverage library.
Colin Cross6e511a92020-07-27 21:26:48 -0700154 CoverageDepTag = dependencyTag{name: "coverage"}
155)
Ivan Lozano183a3212019-10-18 14:18:45 -0700156
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500157// GetImageVariantType returns the ImageVariantType string value for the given module
158// (these are defined in cc/image.go).
159func GetImageVariantType(c LinkableInterface) ImageVariantType {
160 if c.Host() {
161 return hostImageVariant
162 } else if c.InVendor() {
163 return vendorImageVariant
164 } else if c.InProduct() {
165 return productImageVariant
166 } else if c.InRamdisk() {
167 return ramdiskImageVariant
168 } else if c.InVendorRamdisk() {
169 return vendorRamdiskImageVariant
170 } else if c.InRecovery() {
171 return recoveryImageVariant
172 } else {
173 return coreImageVariant
174 }
175}
176
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400177// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
178// Returns an empty string if not a library dependency tag.
179func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
180 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
181 return libDepTag.makeSuffix
182 }
183 return ""
184}
185
Chris Parsons3c27ca32020-11-20 12:42:07 -0500186// SharedDepTag returns the dependency tag for any C++ shared libraries.
Colin Cross6e511a92020-07-27 21:26:48 -0700187func SharedDepTag() blueprint.DependencyTag {
188 return libraryDependencyTag{Kind: sharedLibraryDependency}
Ivan Lozano183a3212019-10-18 14:18:45 -0700189}
190
Chris Parsons3c27ca32020-11-20 12:42:07 -0500191// StaticDepTag returns the dependency tag for any C++ static libraries.
Ivan Lozano63bb7682021-03-23 15:53:44 -0400192func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
193 return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
194}
195
196// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
197func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
198 if tag, ok := depTag.(libraryDependencyTag); ok {
199 return tag.wholeStatic
200 }
201 return false
Colin Cross6e511a92020-07-27 21:26:48 -0700202}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700203
Chris Parsons3c27ca32020-11-20 12:42:07 -0500204// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
Zach Johnson3df4e632020-11-06 11:56:27 -0800205func HeaderDepTag() blueprint.DependencyTag {
206 return libraryDependencyTag{Kind: headerLibraryDependency}
207}
208
Chris Parsons3c27ca32020-11-20 12:42:07 -0500209// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700210type SharedLibraryInfo struct {
211 SharedLibrary android.Path
212 UnstrippedSharedLibrary android.Path
Colin Cross2df81772021-01-26 11:00:18 -0800213 Target android.Target
Colin Cross0de8a1e2020-09-18 14:15:30 -0700214
215 TableOfContents android.OptionalPath
216 CoverageSharedLibrary android.OptionalPath
217
218 StaticAnalogue *StaticLibraryInfo
219}
220
221var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
222
Chris Parsons3c27ca32020-11-20 12:42:07 -0500223// SharedStubLibrary is a struct containing information about a stub shared library.
224// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
225// library in another APEX, it must depend on the stub version of that library.
226type SharedStubLibrary struct {
227 // The version of the stub (corresponding to the stable version of the shared library being
228 // stubbed).
Colin Cross0de8a1e2020-09-18 14:15:30 -0700229 Version string
230 SharedLibraryInfo SharedLibraryInfo
231 FlagExporterInfo FlagExporterInfo
232}
233
Chris Parsons3c27ca32020-11-20 12:42:07 -0500234// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
235// which are dependencies of a library.
236// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
237// library in another APEX, it must depend on the stub version of that library.
238type SharedLibraryStubsInfo struct {
239 SharedStubLibraries []SharedStubLibrary
Colin Cross0de8a1e2020-09-18 14:15:30 -0700240
Chris Parsons3c27ca32020-11-20 12:42:07 -0500241 IsLLNDK bool
242}
243
244var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{})
245
246// StaticLibraryInfo is a provider to propagate information about a static C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700247type StaticLibraryInfo struct {
248 StaticLibrary android.Path
249 Objects Objects
250 ReuseObjects Objects
251
252 // This isn't the actual transitive DepSet, shared library dependencies have been
253 // converted into static library analogues. It is only used to order the static
254 // library dependencies that were specified for the current module.
255 TransitiveStaticLibrariesForOrdering *android.DepSet
256}
257
258var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
259
Colin Cross649d8172020-12-10 12:30:21 -0800260// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
261type HeaderLibraryInfo struct {
262}
263
264// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
265var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{})
266
Chris Parsons3c27ca32020-11-20 12:42:07 -0500267// FlagExporterInfo is a provider to propagate transitive library information
268// pertaining to exported include paths and flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700269type FlagExporterInfo struct {
Chris Parsons3c27ca32020-11-20 12:42:07 -0500270 IncludeDirs android.Paths // Include directories to be included with -I
271 SystemIncludeDirs android.Paths // System include directories to be included with -isystem
272 Flags []string // Exported raw flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700273 Deps android.Paths
274 GeneratedHeaders android.Paths
275}
276
277var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400278
279// flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
280func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
281
282 includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
283 systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
284
285 return FlagExporterInfo{
286 IncludeDirs: includes,
287 SystemIncludeDirs: systemIncludes,
288 }
289}