Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 1 | package cc |
| 2 | |
| 3 | import ( |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 4 | "android/soong/android" |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5 | |
| 6 | "github.com/google/blueprint" |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 7 | ) |
| 8 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 9 | // PlatformSanitizeable is an interface for sanitizing platform modules. |
| 10 | type 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. |
| 60 | type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool |
| 61 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 62 | // LinkableInterface is an interface for a type of module that is linkable in a C++ library. |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 63 | type LinkableInterface interface { |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 64 | android.Module |
| 65 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 66 | Module() android.Module |
| 67 | CcLibrary() bool |
| 68 | CcLibraryInterface() bool |
| 69 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 70 | OutputFile() android.OptionalPath |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 71 | CoverageFiles() android.Paths |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 72 | |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 73 | NonCcVariants() bool |
| 74 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 75 | SelectedStl() string |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 76 | |
| 77 | BuildStaticVariant() bool |
| 78 | BuildSharedVariant() bool |
| 79 | SetStatic() |
| 80 | SetShared() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 81 | Static() bool |
| 82 | Shared() bool |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 83 | Header() bool |
| 84 | IsPrebuilt() bool |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 85 | Toc() android.OptionalPath |
| 86 | |
Jooyung Han | 624d35c | 2020-04-10 12:57:24 +0900 | [diff] [blame] | 87 | Host() bool |
| 88 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 89 | InRamdisk() bool |
| 90 | OnlyInRamdisk() bool |
| 91 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 92 | InVendorRamdisk() bool |
| 93 | OnlyInVendorRamdisk() bool |
| 94 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 95 | InRecovery() bool |
| 96 | OnlyInRecovery() bool |
| 97 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 98 | InVendor() bool |
| 99 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 100 | UseSdk() bool |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 101 | |
| 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 Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 117 | UseVndk() bool |
| 118 | MustUseVendorVariant() bool |
| 119 | IsVndk() bool |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 120 | IsVndkExt() bool |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 121 | IsVndkPrivate() bool |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 122 | HasVendorVariant() bool |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 123 | HasProductVariant() bool |
| 124 | HasNonSystemVariants() bool |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 125 | InProduct() bool |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 126 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame^] | 127 | // SubName returns the modules SubName, used for image and NDK/SDK variations. |
| 128 | SubName() string |
| 129 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 130 | SdkVersion() string |
Jiyong Park | fdaa5f7 | 2021-03-19 22:18:04 +0900 | [diff] [blame] | 131 | MinSdkVersion() string |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 132 | AlwaysSdk() bool |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 133 | IsSdkVariant() bool |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 134 | |
Colin Cross | 1348ce3 | 2020-10-01 13:37:16 -0700 | [diff] [blame] | 135 | SplitPerApiLevel() bool |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 136 | |
| 137 | // SetPreventInstall sets the PreventInstall property to 'true' for this module. |
| 138 | SetPreventInstall() |
| 139 | // SetHideFromMake sets the HideFromMake property to 'true' for this module. |
| 140 | SetHideFromMake() |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 141 | |
| 142 | // KernelHeadersDecorator returns true if this is a kernel headers decorator module. |
| 143 | // This is specific to cc and should always return false for all other packages. |
| 144 | KernelHeadersDecorator() bool |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 147 | var ( |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 148 | // Dependency tag for crtbegin, an object file responsible for initialization. |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 149 | CrtBeginDepTag = dependencyTag{name: "crtbegin"} |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 150 | // Dependency tag for crtend, an object file responsible for program termination. |
| 151 | CrtEndDepTag = dependencyTag{name: "crtend"} |
| 152 | // Dependency tag for coverage library. |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 153 | CoverageDepTag = dependencyTag{name: "coverage"} |
| 154 | ) |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 155 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 156 | // GetImageVariantType returns the ImageVariantType string value for the given module |
| 157 | // (these are defined in cc/image.go). |
| 158 | func GetImageVariantType(c LinkableInterface) ImageVariantType { |
| 159 | if c.Host() { |
| 160 | return hostImageVariant |
| 161 | } else if c.InVendor() { |
| 162 | return vendorImageVariant |
| 163 | } else if c.InProduct() { |
| 164 | return productImageVariant |
| 165 | } else if c.InRamdisk() { |
| 166 | return ramdiskImageVariant |
| 167 | } else if c.InVendorRamdisk() { |
| 168 | return vendorRamdiskImageVariant |
| 169 | } else if c.InRecovery() { |
| 170 | return recoveryImageVariant |
| 171 | } else { |
| 172 | return coreImageVariant |
| 173 | } |
| 174 | } |
| 175 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame^] | 176 | // DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag. |
| 177 | // Returns an empty string if not a library dependency tag. |
| 178 | func DepTagMakeSuffix(depTag blueprint.DependencyTag) string { |
| 179 | if libDepTag, ok := depTag.(libraryDependencyTag); ok { |
| 180 | return libDepTag.makeSuffix |
| 181 | } |
| 182 | return "" |
| 183 | } |
| 184 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 185 | // SharedDepTag returns the dependency tag for any C++ shared libraries. |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 186 | func SharedDepTag() blueprint.DependencyTag { |
| 187 | return libraryDependencyTag{Kind: sharedLibraryDependency} |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 190 | // StaticDepTag returns the dependency tag for any C++ static libraries. |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 191 | func StaticDepTag(wholeStatic bool) blueprint.DependencyTag { |
| 192 | return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic} |
| 193 | } |
| 194 | |
| 195 | // IsWholeStaticLib whether a dependency tag is a whole static library dependency. |
| 196 | func IsWholeStaticLib(depTag blueprint.DependencyTag) bool { |
| 197 | if tag, ok := depTag.(libraryDependencyTag); ok { |
| 198 | return tag.wholeStatic |
| 199 | } |
| 200 | return false |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 201 | } |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 202 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 203 | // HeaderDepTag returns the dependency tag for any C++ "header-only" libraries. |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 204 | func HeaderDepTag() blueprint.DependencyTag { |
| 205 | return libraryDependencyTag{Kind: headerLibraryDependency} |
| 206 | } |
| 207 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 208 | // SharedLibraryInfo is a provider to propagate information about a shared C++ library. |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 209 | type SharedLibraryInfo struct { |
| 210 | SharedLibrary android.Path |
| 211 | UnstrippedSharedLibrary android.Path |
| 212 | |
| 213 | TableOfContents android.OptionalPath |
| 214 | CoverageSharedLibrary android.OptionalPath |
| 215 | |
| 216 | StaticAnalogue *StaticLibraryInfo |
| 217 | } |
| 218 | |
| 219 | var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{}) |
| 220 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 221 | // SharedStubLibrary is a struct containing information about a stub shared 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. |
| 224 | type SharedStubLibrary struct { |
| 225 | // The version of the stub (corresponding to the stable version of the shared library being |
| 226 | // stubbed). |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 227 | Version string |
| 228 | SharedLibraryInfo SharedLibraryInfo |
| 229 | FlagExporterInfo FlagExporterInfo |
| 230 | } |
| 231 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 232 | // SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs |
| 233 | // which are dependencies of a library. |
| 234 | // Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared |
| 235 | // library in another APEX, it must depend on the stub version of that library. |
| 236 | type SharedLibraryStubsInfo struct { |
| 237 | SharedStubLibraries []SharedStubLibrary |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 238 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 239 | IsLLNDK bool |
| 240 | } |
| 241 | |
| 242 | var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{}) |
| 243 | |
| 244 | // StaticLibraryInfo is a provider to propagate information about a static C++ library. |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 245 | type StaticLibraryInfo struct { |
| 246 | StaticLibrary android.Path |
| 247 | Objects Objects |
| 248 | ReuseObjects Objects |
| 249 | |
| 250 | // This isn't the actual transitive DepSet, shared library dependencies have been |
| 251 | // converted into static library analogues. It is only used to order the static |
| 252 | // library dependencies that were specified for the current module. |
| 253 | TransitiveStaticLibrariesForOrdering *android.DepSet |
| 254 | } |
| 255 | |
| 256 | var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{}) |
| 257 | |
Colin Cross | 649d817 | 2020-12-10 12:30:21 -0800 | [diff] [blame] | 258 | // HeaderLibraryInfo is a marker provider that identifies a module as a header library. |
| 259 | type HeaderLibraryInfo struct { |
| 260 | } |
| 261 | |
| 262 | // HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library. |
| 263 | var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{}) |
| 264 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 265 | // FlagExporterInfo is a provider to propagate transitive library information |
| 266 | // pertaining to exported include paths and flags. |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 267 | type FlagExporterInfo struct { |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 268 | IncludeDirs android.Paths // Include directories to be included with -I |
| 269 | SystemIncludeDirs android.Paths // System include directories to be included with -isystem |
| 270 | Flags []string // Exported raw flags. |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 271 | Deps android.Paths |
| 272 | GeneratedHeaders android.Paths |
| 273 | } |
| 274 | |
| 275 | var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{}) |