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" |
Liz Kammer | b6a55bf | 2021-04-12 15:42:51 -0400 | [diff] [blame] | 5 | "android/soong/bazel/cquery" |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 6 | |
| 7 | "github.com/google/blueprint" |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 8 | ) |
| 9 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 10 | // PlatformSanitizeable is an interface for sanitizing platform modules. |
| 11 | type 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. |
| 61 | type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool |
| 62 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 63 | // 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] | 64 | type LinkableInterface interface { |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 65 | android.Module |
| 66 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 67 | Module() android.Module |
| 68 | CcLibrary() bool |
| 69 | CcLibraryInterface() bool |
| 70 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 71 | OutputFile() android.OptionalPath |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 72 | CoverageFiles() android.Paths |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 73 | |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 74 | NonCcVariants() bool |
| 75 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 76 | SelectedStl() string |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 77 | |
| 78 | BuildStaticVariant() bool |
| 79 | BuildSharedVariant() bool |
| 80 | SetStatic() |
| 81 | SetShared() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 82 | Static() bool |
| 83 | Shared() bool |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 84 | Header() bool |
| 85 | IsPrebuilt() bool |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 86 | Toc() android.OptionalPath |
| 87 | |
Jooyung Han | 624d35c | 2020-04-10 12:57:24 +0900 | [diff] [blame] | 88 | Host() bool |
| 89 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 90 | InRamdisk() bool |
| 91 | OnlyInRamdisk() bool |
| 92 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 93 | InVendorRamdisk() bool |
| 94 | OnlyInVendorRamdisk() bool |
| 95 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 96 | InRecovery() bool |
| 97 | OnlyInRecovery() bool |
| 98 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 99 | InVendor() bool |
| 100 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 101 | UseSdk() bool |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 102 | |
| 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 Cross | 1f3f130 | 2021-04-26 18:37:44 -0700 | [diff] [blame^] | 115 | // NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers. |
| 116 | NeedsLlndkVariants() bool |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 117 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 118 | UseVndk() bool |
| 119 | MustUseVendorVariant() bool |
| 120 | IsVndk() bool |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 121 | IsVndkExt() bool |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 122 | IsVndkPrivate() bool |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 123 | HasVendorVariant() bool |
Justin Yun | cbca373 | 2021-02-03 19:24:13 +0900 | [diff] [blame] | 124 | HasProductVariant() bool |
| 125 | HasNonSystemVariants() bool |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 126 | InProduct() bool |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 127 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 128 | // SubName returns the modules SubName, used for image and NDK/SDK variations. |
| 129 | SubName() string |
| 130 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 131 | SdkVersion() string |
Jiyong Park | fdaa5f7 | 2021-03-19 22:18:04 +0900 | [diff] [blame] | 132 | MinSdkVersion() string |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 133 | AlwaysSdk() bool |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 134 | IsSdkVariant() bool |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 135 | |
Colin Cross | 1348ce3 | 2020-10-01 13:37:16 -0700 | [diff] [blame] | 136 | SplitPerApiLevel() bool |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 137 | |
| 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 Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 142 | |
| 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 Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 148 | var ( |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 149 | // Dependency tag for crtbegin, an object file responsible for initialization. |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 150 | CrtBeginDepTag = dependencyTag{name: "crtbegin"} |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 151 | // Dependency tag for crtend, an object file responsible for program termination. |
| 152 | CrtEndDepTag = dependencyTag{name: "crtend"} |
| 153 | // Dependency tag for coverage library. |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 154 | CoverageDepTag = dependencyTag{name: "coverage"} |
| 155 | ) |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 156 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 157 | // GetImageVariantType returns the ImageVariantType string value for the given module |
| 158 | // (these are defined in cc/image.go). |
| 159 | func 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 Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 177 | // DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag. |
| 178 | // Returns an empty string if not a library dependency tag. |
| 179 | func DepTagMakeSuffix(depTag blueprint.DependencyTag) string { |
| 180 | if libDepTag, ok := depTag.(libraryDependencyTag); ok { |
| 181 | return libDepTag.makeSuffix |
| 182 | } |
| 183 | return "" |
| 184 | } |
| 185 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 186 | // SharedDepTag returns the dependency tag for any C++ shared libraries. |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 187 | func SharedDepTag() blueprint.DependencyTag { |
| 188 | return libraryDependencyTag{Kind: sharedLibraryDependency} |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 191 | // StaticDepTag returns the dependency tag for any C++ static libraries. |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 192 | func 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. |
| 197 | func IsWholeStaticLib(depTag blueprint.DependencyTag) bool { |
| 198 | if tag, ok := depTag.(libraryDependencyTag); ok { |
| 199 | return tag.wholeStatic |
| 200 | } |
| 201 | return false |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 202 | } |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 203 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 204 | // HeaderDepTag returns the dependency tag for any C++ "header-only" libraries. |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 205 | func HeaderDepTag() blueprint.DependencyTag { |
| 206 | return libraryDependencyTag{Kind: headerLibraryDependency} |
| 207 | } |
| 208 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 209 | // SharedLibraryInfo is a provider to propagate information about a shared C++ library. |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 210 | type SharedLibraryInfo struct { |
| 211 | SharedLibrary android.Path |
| 212 | UnstrippedSharedLibrary android.Path |
Colin Cross | 2df8177 | 2021-01-26 11:00:18 -0800 | [diff] [blame] | 213 | Target android.Target |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 214 | |
| 215 | TableOfContents android.OptionalPath |
| 216 | CoverageSharedLibrary android.OptionalPath |
| 217 | |
| 218 | StaticAnalogue *StaticLibraryInfo |
| 219 | } |
| 220 | |
| 221 | var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{}) |
| 222 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 223 | // 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. |
| 226 | type SharedStubLibrary struct { |
| 227 | // The version of the stub (corresponding to the stable version of the shared library being |
| 228 | // stubbed). |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 229 | Version string |
| 230 | SharedLibraryInfo SharedLibraryInfo |
| 231 | FlagExporterInfo FlagExporterInfo |
| 232 | } |
| 233 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 234 | // 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. |
| 238 | type SharedLibraryStubsInfo struct { |
| 239 | SharedStubLibraries []SharedStubLibrary |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 240 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 241 | IsLLNDK bool |
| 242 | } |
| 243 | |
| 244 | var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{}) |
| 245 | |
| 246 | // StaticLibraryInfo is a provider to propagate information about a static C++ library. |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 247 | type 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 | |
| 258 | var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{}) |
| 259 | |
Colin Cross | 649d817 | 2020-12-10 12:30:21 -0800 | [diff] [blame] | 260 | // HeaderLibraryInfo is a marker provider that identifies a module as a header library. |
| 261 | type HeaderLibraryInfo struct { |
| 262 | } |
| 263 | |
| 264 | // HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library. |
| 265 | var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{}) |
| 266 | |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 267 | // FlagExporterInfo is a provider to propagate transitive library information |
| 268 | // pertaining to exported include paths and flags. |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 269 | type FlagExporterInfo struct { |
Chris Parsons | 3c27ca3 | 2020-11-20 12:42:07 -0500 | [diff] [blame] | 270 | 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 Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 273 | Deps android.Paths |
| 274 | GeneratedHeaders android.Paths |
| 275 | } |
| 276 | |
| 277 | var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{}) |
Liz Kammer | b6a55bf | 2021-04-12 15:42:51 -0400 | [diff] [blame] | 278 | |
| 279 | // flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel. |
| 280 | func 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 | } |