blob: 17bafcc41fd0517565ff70f7c849d2e86468c453 [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"
Colin Cross6e511a92020-07-27 21:26:48 -07005
6 "github.com/google/blueprint"
Ivan Lozano183a3212019-10-18 14:18:45 -07007)
8
Ivan Lozano3968d8f2020-12-14 11:27:52 -05009// PlatformSanitizeable is an interface for sanitizing platform modules.
10type PlatformSanitizeable interface {
11 LinkableInterface
12
13 // SanitizePropDefined returns whether the Sanitizer properties struct for this module is defined.
14 SanitizePropDefined() bool
15
16 // IsDependencyRoot returns whether a module is of a type which cannot be a linkage dependency
17 // of another module. For example, cc_binary and rust_binary represent dependency roots as other
18 // modules cannot have linkage dependencies against these types.
19 IsDependencyRoot() bool
20
21 // IsSanitizerEnabled returns whether a sanitizer is enabled.
22 IsSanitizerEnabled(t SanitizerType) bool
23
24 // IsSanitizerExplicitlyDisabled returns whether a sanitizer has been explicitly disabled (set to false) rather
25 // than left undefined.
26 IsSanitizerExplicitlyDisabled(t SanitizerType) bool
27
28 // SanitizeDep returns the value of the SanitizeDep flag, which is set if a module is a dependency of a
29 // sanitized module.
30 SanitizeDep() bool
31
32 // SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
33 SetSanitizer(t SanitizerType, b bool)
34
35 // SetSanitizerDep returns true if the module is statically linked.
36 SetSanitizeDep(b bool)
37
38 // StaticallyLinked returns true if the module is statically linked.
39 StaticallyLinked() bool
40
41 // SetInSanitizerDir sets the module installation to the sanitizer directory.
42 SetInSanitizerDir()
43
44 // SanitizeNever returns true if this module should never be sanitized.
45 SanitizeNever() bool
46
47 // SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
48 SanitizerSupported(t SanitizerType) bool
49
50 // SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
51 SanitizableDepTagChecker() SantizableDependencyTagChecker
52}
53
54// SantizableDependencyTagChecker functions check whether or not a dependency
55// tag can be sanitized. These functions should return true if the tag can be
56// sanitized, otherwise they should return false. These functions should also
57// handle all possible dependency tags in the dependency tree. For example,
58// Rust modules can depend on both Rust and CC libraries, so the Rust module
59// implementation should handle tags from both.
60type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
61
Chris Parsons3c27ca32020-11-20 12:42:07 -050062// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
Ivan Lozano183a3212019-10-18 14:18:45 -070063type LinkableInterface interface {
Ivan Lozanof9e21722020-12-02 09:00:51 -050064 android.Module
65
Ivan Lozano183a3212019-10-18 14:18:45 -070066 Module() android.Module
67 CcLibrary() bool
68 CcLibraryInterface() bool
69
Ivan Lozano183a3212019-10-18 14:18:45 -070070 OutputFile() android.OptionalPath
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -040071 CoverageFiles() android.Paths
Ivan Lozano183a3212019-10-18 14:18:45 -070072
Ivan Lozano2b262972019-11-21 12:30:50 -080073 NonCcVariants() bool
74
Ivan Lozano52767be2019-10-18 14:49:46 -070075 SelectedStl() string
Ivan Lozano183a3212019-10-18 14:18:45 -070076
77 BuildStaticVariant() bool
78 BuildSharedVariant() bool
79 SetStatic()
80 SetShared()
Ivan Lozano52767be2019-10-18 14:49:46 -070081 Static() bool
82 Shared() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -050083 Header() bool
84 IsPrebuilt() bool
Ivan Lozano52767be2019-10-18 14:49:46 -070085 Toc() android.OptionalPath
86
Jooyung Han624d35c2020-04-10 12:57:24 +090087 Host() bool
88
Yifan Hong1b3348d2020-01-21 15:53:22 -080089 InRamdisk() bool
90 OnlyInRamdisk() bool
91
Yifan Hong60e0cfb2020-10-21 15:17:56 -070092 InVendorRamdisk() bool
93 OnlyInVendorRamdisk() bool
94
Ivan Lozano52767be2019-10-18 14:49:46 -070095 InRecovery() bool
96 OnlyInRecovery() bool
97
Ivan Lozano3968d8f2020-12-14 11:27:52 -050098 InVendor() bool
99
Colin Crossc511bc52020-04-07 16:50:32 +0000100 UseSdk() bool
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400101
102 // IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
103 IsLlndk() bool
104
105 // IsLlndkPublic returns true only for LLNDK (public) libs.
106 IsLlndkPublic() bool
107
108 // IsLlndkHeaders returns true if this module is an LLNDK headers module.
109 IsLlndkHeaders() bool
110
111 // IsLlndkLibrary returns true if this module is an LLNDK library module.
112 IsLlndkLibrary() bool
113
114 // HasLlndkStubs returns true if this module has LLNDK stubs.
115 HasLlndkStubs() bool
116
Ivan Lozano52767be2019-10-18 14:49:46 -0700117 UseVndk() bool
118 MustUseVendorVariant() bool
119 IsVndk() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500120 IsVndkExt() bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800121 IsVndkPrivate() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700122 HasVendorVariant() bool
Justin Yuncbca3732021-02-03 19:24:13 +0900123 HasProductVariant() bool
124 HasNonSystemVariants() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500125 InProduct() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700126
127 SdkVersion() string
Jiyong Parkfdaa5f72021-03-19 22:18:04 +0900128 MinSdkVersion() string
Colin Crossc511bc52020-04-07 16:50:32 +0000129 AlwaysSdk() bool
Jiyong Park2286afd2020-06-16 21:58:53 +0900130 IsSdkVariant() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700131
Colin Cross1348ce32020-10-01 13:37:16 -0700132 SplitPerApiLevel() bool
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500133
134 // SetPreventInstall sets the PreventInstall property to 'true' for this module.
135 SetPreventInstall()
136 // SetHideFromMake sets the HideFromMake property to 'true' for this module.
137 SetHideFromMake()
Ivan Lozano3a7d0002021-03-30 12:19:36 -0400138
139 // KernelHeadersDecorator returns true if this is a kernel headers decorator module.
140 // This is specific to cc and should always return false for all other packages.
141 KernelHeadersDecorator() bool
Ivan Lozano183a3212019-10-18 14:18:45 -0700142}
143
Colin Cross6e511a92020-07-27 21:26:48 -0700144var (
Chris Parsons3c27ca32020-11-20 12:42:07 -0500145 // Dependency tag for crtbegin, an object file responsible for initialization.
Colin Cross6e511a92020-07-27 21:26:48 -0700146 CrtBeginDepTag = dependencyTag{name: "crtbegin"}
Chris Parsons3c27ca32020-11-20 12:42:07 -0500147 // Dependency tag for crtend, an object file responsible for program termination.
148 CrtEndDepTag = dependencyTag{name: "crtend"}
149 // Dependency tag for coverage library.
Colin Cross6e511a92020-07-27 21:26:48 -0700150 CoverageDepTag = dependencyTag{name: "coverage"}
151)
Ivan Lozano183a3212019-10-18 14:18:45 -0700152
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500153// GetImageVariantType returns the ImageVariantType string value for the given module
154// (these are defined in cc/image.go).
155func GetImageVariantType(c LinkableInterface) ImageVariantType {
156 if c.Host() {
157 return hostImageVariant
158 } else if c.InVendor() {
159 return vendorImageVariant
160 } else if c.InProduct() {
161 return productImageVariant
162 } else if c.InRamdisk() {
163 return ramdiskImageVariant
164 } else if c.InVendorRamdisk() {
165 return vendorRamdiskImageVariant
166 } else if c.InRecovery() {
167 return recoveryImageVariant
168 } else {
169 return coreImageVariant
170 }
171}
172
Chris Parsons3c27ca32020-11-20 12:42:07 -0500173// SharedDepTag returns the dependency tag for any C++ shared libraries.
Colin Cross6e511a92020-07-27 21:26:48 -0700174func SharedDepTag() blueprint.DependencyTag {
175 return libraryDependencyTag{Kind: sharedLibraryDependency}
Ivan Lozano183a3212019-10-18 14:18:45 -0700176}
177
Chris Parsons3c27ca32020-11-20 12:42:07 -0500178// StaticDepTag returns the dependency tag for any C++ static libraries.
Ivan Lozano63bb7682021-03-23 15:53:44 -0400179func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
180 return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
181}
182
183// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
184func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
185 if tag, ok := depTag.(libraryDependencyTag); ok {
186 return tag.wholeStatic
187 }
188 return false
Colin Cross6e511a92020-07-27 21:26:48 -0700189}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700190
Chris Parsons3c27ca32020-11-20 12:42:07 -0500191// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
Zach Johnson3df4e632020-11-06 11:56:27 -0800192func HeaderDepTag() blueprint.DependencyTag {
193 return libraryDependencyTag{Kind: headerLibraryDependency}
194}
195
Chris Parsons3c27ca32020-11-20 12:42:07 -0500196// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700197type SharedLibraryInfo struct {
198 SharedLibrary android.Path
199 UnstrippedSharedLibrary android.Path
200
201 TableOfContents android.OptionalPath
202 CoverageSharedLibrary android.OptionalPath
203
204 StaticAnalogue *StaticLibraryInfo
205}
206
207var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
208
Chris Parsons3c27ca32020-11-20 12:42:07 -0500209// SharedStubLibrary is a struct containing information about a stub shared library.
210// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
211// library in another APEX, it must depend on the stub version of that library.
212type SharedStubLibrary struct {
213 // The version of the stub (corresponding to the stable version of the shared library being
214 // stubbed).
Colin Cross0de8a1e2020-09-18 14:15:30 -0700215 Version string
216 SharedLibraryInfo SharedLibraryInfo
217 FlagExporterInfo FlagExporterInfo
218}
219
Chris Parsons3c27ca32020-11-20 12:42:07 -0500220// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
221// which are dependencies of a library.
222// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
223// library in another APEX, it must depend on the stub version of that library.
224type SharedLibraryStubsInfo struct {
225 SharedStubLibraries []SharedStubLibrary
Colin Cross0de8a1e2020-09-18 14:15:30 -0700226
Chris Parsons3c27ca32020-11-20 12:42:07 -0500227 IsLLNDK bool
228}
229
230var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{})
231
232// StaticLibraryInfo is a provider to propagate information about a static C++ library.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700233type StaticLibraryInfo struct {
234 StaticLibrary android.Path
235 Objects Objects
236 ReuseObjects Objects
237
238 // This isn't the actual transitive DepSet, shared library dependencies have been
239 // converted into static library analogues. It is only used to order the static
240 // library dependencies that were specified for the current module.
241 TransitiveStaticLibrariesForOrdering *android.DepSet
242}
243
244var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
245
Colin Cross649d8172020-12-10 12:30:21 -0800246// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
247type HeaderLibraryInfo struct {
248}
249
250// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
251var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{})
252
Chris Parsons3c27ca32020-11-20 12:42:07 -0500253// FlagExporterInfo is a provider to propagate transitive library information
254// pertaining to exported include paths and flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700255type FlagExporterInfo struct {
Chris Parsons3c27ca32020-11-20 12:42:07 -0500256 IncludeDirs android.Paths // Include directories to be included with -I
257 SystemIncludeDirs android.Paths // System include directories to be included with -isystem
258 Flags []string // Exported raw flags.
Colin Cross0de8a1e2020-09-18 14:15:30 -0700259 Deps android.Paths
260 GeneratedHeaders android.Paths
261}
262
263var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})