blob: 6f6410a5b84d0ad6f58fd4aacec9c71345425afe [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
Colin Cross1f3f1302021-04-26 18:37:44 -0700109 // NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
110 NeedsLlndkVariants() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400111
Ivan Lozano52767be2019-10-18 14:49:46 -0700112 UseVndk() bool
113 MustUseVendorVariant() bool
114 IsVndk() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500115 IsVndkExt() bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800116 IsVndkPrivate() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700117 HasVendorVariant() bool
Justin Yuncbca3732021-02-03 19:24:13 +0900118 HasProductVariant() bool
119 HasNonSystemVariants() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500120 InProduct() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700121
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400122 // SubName returns the modules SubName, used for image and NDK/SDK variations.
123 SubName() string
124
Ivan Lozano52767be2019-10-18 14:49:46 -0700125 SdkVersion() string
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900126 MinSdkVersion() string
Colin Crossc511bc52020-04-07 16:50:32 +0000127 AlwaysSdk() bool
Jiyong Park2286afd2020-06-16 21:58:53 +0900128 IsSdkVariant() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700129
Colin Cross1348ce32020-10-01 13:37:16 -0700130 SplitPerApiLevel() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500131
132 // SetPreventInstall sets the PreventInstall property to 'true' for this module.
133 SetPreventInstall()
134 // SetHideFromMake sets the HideFromMake property to 'true' for this module.
135 SetHideFromMake()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400136
137 // KernelHeadersDecorator returns true if this is a kernel headers decorator module.
138 // This is specific to cc and should always return false for all other packages.
139 KernelHeadersDecorator() bool
Ivan Lozano183a3212019-10-18 14:18:45 -0700140}
141
Colin Cross6e511a92020-07-27 21:26:48 -0700142var (
Chris Parsons3c27ca32020-11-20 12:42:07 -0500143 // Dependency tag for crtbegin, an object file responsible for initialization.
Colin Cross6e511a92020-07-27 21:26:48 -0700144 CrtBeginDepTag = dependencyTag{name: "crtbegin"}
Chris Parsons3c27ca32020-11-20 12:42:07 -0500145 // Dependency tag for crtend, an object file responsible for program termination.
146 CrtEndDepTag = dependencyTag{name: "crtend"}
147 // Dependency tag for coverage library.
Colin Cross6e511a92020-07-27 21:26:48 -0700148 CoverageDepTag = dependencyTag{name: "coverage"}
149)
Ivan Lozano183a3212019-10-18 14:18:45 -0700150
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500151// GetImageVariantType returns the ImageVariantType string value for the given module
152// (these are defined in cc/image.go).
153func GetImageVariantType(c LinkableInterface) ImageVariantType {
154 if c.Host() {
155 return hostImageVariant
156 } else if c.InVendor() {
157 return vendorImageVariant
158 } else if c.InProduct() {
159 return productImageVariant
160 } else if c.InRamdisk() {
161 return ramdiskImageVariant
162 } else if c.InVendorRamdisk() {
163 return vendorRamdiskImageVariant
164 } else if c.InRecovery() {
165 return recoveryImageVariant
166 } else {
167 return coreImageVariant
168 }
169}
170
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400171// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
172// Returns an empty string if not a library dependency tag.
173func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
174 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
175 return libDepTag.makeSuffix
176 }
177 return ""
178}
179
Chris Parsons3c27ca32020-11-20 12:42:07 -0500180// SharedDepTag returns the dependency tag for any C++ shared libraries.
Colin Cross6e511a92020-07-27 21:26:48 -0700181func SharedDepTag() blueprint.DependencyTag {
182 return libraryDependencyTag{Kind: sharedLibraryDependency}
Ivan Lozano183a3212019-10-18 14:18:45 -0700183}
184
Chris Parsons3c27ca32020-11-20 12:42:07 -0500185// StaticDepTag returns the dependency tag for any C++ static libraries.
Ivan Lozano63bb7682021-03-23 15:53:44 -0400186func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
187 return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
188}
189
190// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
191func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
192 if tag, ok := depTag.(libraryDependencyTag); ok {
193 return tag.wholeStatic
194 }
195 return false
Colin Cross6e511a92020-07-27 21:26:48 -0700196}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700197
Chris Parsons3c27ca32020-11-20 12:42:07 -0500198// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
Zach Johnson3df4e632020-11-06 11:56:27 -0800199func HeaderDepTag() blueprint.DependencyTag {
200 return libraryDependencyTag{Kind: headerLibraryDependency}
201}
202
Chris Parsons3c27ca32020-11-20 12:42:07 -0500203// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700204type SharedLibraryInfo struct {
205 SharedLibrary android.Path
206 UnstrippedSharedLibrary android.Path
Colin Cross2df81772021-01-26 11:00:18 -0800207 Target android.Target
Colin Cross0de8a1e2020-09-18 14:15:30 -0700208
209 TableOfContents android.OptionalPath
210 CoverageSharedLibrary android.OptionalPath
211
212 StaticAnalogue *StaticLibraryInfo
213}
214
215var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
216
Chris Parsons3c27ca32020-11-20 12:42:07 -0500217// SharedStubLibrary is a struct containing information about a stub shared library.
218// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
219// library in another APEX, it must depend on the stub version of that library.
220type SharedStubLibrary struct {
221 // The version of the stub (corresponding to the stable version of the shared library being
222 // stubbed).
Colin Cross0de8a1e2020-09-18 14:15:30 -0700223 Version string
224 SharedLibraryInfo SharedLibraryInfo
225 FlagExporterInfo FlagExporterInfo
226}
227
Chris Parsons3c27ca32020-11-20 12:42:07 -0500228// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
229// which are dependencies of a library.
230// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
231// library in another APEX, it must depend on the stub version of that library.
232type SharedLibraryStubsInfo struct {
233 SharedStubLibraries []SharedStubLibrary
Colin Cross0de8a1e2020-09-18 14:15:30 -0700234
Chris Parsons3c27ca32020-11-20 12:42:07 -0500235 IsLLNDK bool
236}
237
238var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{})
239
240// StaticLibraryInfo is a provider to propagate information about a static C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700241type StaticLibraryInfo struct {
242 StaticLibrary android.Path
243 Objects Objects
244 ReuseObjects Objects
245
246 // This isn't the actual transitive DepSet, shared library dependencies have been
247 // converted into static library analogues. It is only used to order the static
248 // library dependencies that were specified for the current module.
249 TransitiveStaticLibrariesForOrdering *android.DepSet
250}
251
252var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
253
Colin Cross649d8172020-12-10 12:30:21 -0800254// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
255type HeaderLibraryInfo struct {
256}
257
258// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
259var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{})
260
Chris Parsons3c27ca32020-11-20 12:42:07 -0500261// FlagExporterInfo is a provider to propagate transitive library information
262// pertaining to exported include paths and flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700263type FlagExporterInfo struct {
Chris Parsons3c27ca32020-11-20 12:42:07 -0500264 IncludeDirs android.Paths // Include directories to be included with -I
265 SystemIncludeDirs android.Paths // System include directories to be included with -isystem
266 Flags []string // Exported raw flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700267 Deps android.Paths
268 GeneratedHeaders android.Paths
269}
270
271var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400272
273// flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
274func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
275
276 includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
277 systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
278
279 return FlagExporterInfo{
280 IncludeDirs: includes,
281 SystemIncludeDirs: systemIncludes,
282 }
283}