blob: 40a9d8b048f88b13e8b1fb25d946a6d2cfe33e90 [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
Colin Cross5271fea2021-04-27 13:06:04 -0700112 // NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
113 NeedsVendorPublicLibraryVariants() bool
114
Ivan Lozano52767be2019-10-18 14:49:46 -0700115 UseVndk() bool
116 MustUseVendorVariant() bool
117 IsVndk() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500118 IsVndkExt() bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800119 IsVndkPrivate() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700120 HasVendorVariant() bool
Justin Yuncbca3732021-02-03 19:24:13 +0900121 HasProductVariant() bool
122 HasNonSystemVariants() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500123 InProduct() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700124
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400125 // SubName returns the modules SubName, used for image and NDK/SDK variations.
126 SubName() string
127
Ivan Lozano52767be2019-10-18 14:49:46 -0700128 SdkVersion() string
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900129 MinSdkVersion() string
Colin Crossc511bc52020-04-07 16:50:32 +0000130 AlwaysSdk() bool
Jiyong Park2286afd2020-06-16 21:58:53 +0900131 IsSdkVariant() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700132
Colin Cross1348ce32020-10-01 13:37:16 -0700133 SplitPerApiLevel() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500134
135 // SetPreventInstall sets the PreventInstall property to 'true' for this module.
136 SetPreventInstall()
137 // SetHideFromMake sets the HideFromMake property to 'true' for this module.
138 SetHideFromMake()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400139
140 // KernelHeadersDecorator returns true if this is a kernel headers decorator module.
141 // This is specific to cc and should always return false for all other packages.
142 KernelHeadersDecorator() bool
Ivan Lozano183a3212019-10-18 14:18:45 -0700143}
144
Colin Cross6e511a92020-07-27 21:26:48 -0700145var (
Chris Parsons3c27ca32020-11-20 12:42:07 -0500146 // Dependency tag for crtbegin, an object file responsible for initialization.
Colin Cross6e511a92020-07-27 21:26:48 -0700147 CrtBeginDepTag = dependencyTag{name: "crtbegin"}
Chris Parsons3c27ca32020-11-20 12:42:07 -0500148 // Dependency tag for crtend, an object file responsible for program termination.
149 CrtEndDepTag = dependencyTag{name: "crtend"}
150 // Dependency tag for coverage library.
Colin Cross6e511a92020-07-27 21:26:48 -0700151 CoverageDepTag = dependencyTag{name: "coverage"}
152)
Ivan Lozano183a3212019-10-18 14:18:45 -0700153
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500154// GetImageVariantType returns the ImageVariantType string value for the given module
155// (these are defined in cc/image.go).
156func GetImageVariantType(c LinkableInterface) ImageVariantType {
157 if c.Host() {
158 return hostImageVariant
159 } else if c.InVendor() {
160 return vendorImageVariant
161 } else if c.InProduct() {
162 return productImageVariant
163 } else if c.InRamdisk() {
164 return ramdiskImageVariant
165 } else if c.InVendorRamdisk() {
166 return vendorRamdiskImageVariant
167 } else if c.InRecovery() {
168 return recoveryImageVariant
169 } else {
170 return coreImageVariant
171 }
172}
173
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400174// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
175// Returns an empty string if not a library dependency tag.
176func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
177 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
178 return libDepTag.makeSuffix
179 }
180 return ""
181}
182
Chris Parsons3c27ca32020-11-20 12:42:07 -0500183// SharedDepTag returns the dependency tag for any C++ shared libraries.
Colin Cross6e511a92020-07-27 21:26:48 -0700184func SharedDepTag() blueprint.DependencyTag {
185 return libraryDependencyTag{Kind: sharedLibraryDependency}
Ivan Lozano183a3212019-10-18 14:18:45 -0700186}
187
Chris Parsons3c27ca32020-11-20 12:42:07 -0500188// StaticDepTag returns the dependency tag for any C++ static libraries.
Ivan Lozano63bb7682021-03-23 15:53:44 -0400189func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
190 return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
191}
192
193// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
194func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
195 if tag, ok := depTag.(libraryDependencyTag); ok {
196 return tag.wholeStatic
197 }
198 return false
Colin Cross6e511a92020-07-27 21:26:48 -0700199}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700200
Chris Parsons3c27ca32020-11-20 12:42:07 -0500201// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
Zach Johnson3df4e632020-11-06 11:56:27 -0800202func HeaderDepTag() blueprint.DependencyTag {
203 return libraryDependencyTag{Kind: headerLibraryDependency}
204}
205
Chris Parsons3c27ca32020-11-20 12:42:07 -0500206// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700207type SharedLibraryInfo struct {
208 SharedLibrary android.Path
209 UnstrippedSharedLibrary android.Path
Colin Cross2df81772021-01-26 11:00:18 -0800210 Target android.Target
Colin Cross0de8a1e2020-09-18 14:15:30 -0700211
212 TableOfContents android.OptionalPath
213 CoverageSharedLibrary android.OptionalPath
214
215 StaticAnalogue *StaticLibraryInfo
216}
217
218var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
219
Chris Parsons3c27ca32020-11-20 12:42:07 -0500220// SharedStubLibrary is a struct containing information about a stub shared library.
221// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
222// library in another APEX, it must depend on the stub version of that library.
223type SharedStubLibrary struct {
224 // The version of the stub (corresponding to the stable version of the shared library being
225 // stubbed).
Colin Cross0de8a1e2020-09-18 14:15:30 -0700226 Version string
227 SharedLibraryInfo SharedLibraryInfo
228 FlagExporterInfo FlagExporterInfo
229}
230
Chris Parsons3c27ca32020-11-20 12:42:07 -0500231// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
232// which are dependencies of a library.
233// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
234// library in another APEX, it must depend on the stub version of that library.
235type SharedLibraryStubsInfo struct {
236 SharedStubLibraries []SharedStubLibrary
Colin Cross0de8a1e2020-09-18 14:15:30 -0700237
Chris Parsons3c27ca32020-11-20 12:42:07 -0500238 IsLLNDK bool
239}
240
241var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{})
242
243// StaticLibraryInfo is a provider to propagate information about a static C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700244type StaticLibraryInfo struct {
245 StaticLibrary android.Path
246 Objects Objects
247 ReuseObjects Objects
248
249 // This isn't the actual transitive DepSet, shared library dependencies have been
250 // converted into static library analogues. It is only used to order the static
251 // library dependencies that were specified for the current module.
252 TransitiveStaticLibrariesForOrdering *android.DepSet
253}
254
255var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
256
Colin Cross649d8172020-12-10 12:30:21 -0800257// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
258type HeaderLibraryInfo struct {
259}
260
261// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
262var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{})
263
Chris Parsons3c27ca32020-11-20 12:42:07 -0500264// FlagExporterInfo is a provider to propagate transitive library information
265// pertaining to exported include paths and flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700266type FlagExporterInfo struct {
Chris Parsons3c27ca32020-11-20 12:42:07 -0500267 IncludeDirs android.Paths // Include directories to be included with -I
268 SystemIncludeDirs android.Paths // System include directories to be included with -isystem
269 Flags []string // Exported raw flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700270 Deps android.Paths
271 GeneratedHeaders android.Paths
272}
273
274var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400275
276// flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
277func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
278
279 includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
280 systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
281
282 return FlagExporterInfo{
Chris Parsonsf60ecf02021-04-27 14:48:30 -0400283 IncludeDirs: android.FirstUniquePaths(includes),
284 SystemIncludeDirs: android.FirstUniquePaths(systemIncludes),
Liz Kammerb6a55bf2021-04-12 15:42:51 -0400285 }
286}