linkable.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. package cc
  2. import (
  3. "android/soong/android"
  4. "android/soong/bazel/cquery"
  5. "android/soong/fuzz"
  6. "android/soong/snapshot"
  7. "github.com/google/blueprint"
  8. )
  9. // PlatformSanitizeable is an interface for sanitizing platform modules.
  10. type PlatformSanitizeable interface {
  11. LinkableInterface
  12. // SanitizePropDefined returns whether the Sanitizer properties struct for this module is defined.
  13. SanitizePropDefined() bool
  14. // IsSanitizerEnabled returns whether a sanitizer is enabled.
  15. IsSanitizerEnabled(t SanitizerType) bool
  16. // IsSanitizerExplicitlyDisabled returns whether a sanitizer has been explicitly disabled (set to false) rather
  17. // than left undefined.
  18. IsSanitizerExplicitlyDisabled(t SanitizerType) bool
  19. // SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
  20. SetSanitizer(t SanitizerType, b bool)
  21. // StaticallyLinked returns true if the module is statically linked.
  22. StaticallyLinked() bool
  23. // SetInSanitizerDir sets the module installation to the sanitizer directory.
  24. SetInSanitizerDir()
  25. // SanitizeNever returns true if this module should never be sanitized.
  26. SanitizeNever() bool
  27. // SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
  28. SanitizerSupported(t SanitizerType) bool
  29. // MinimalRuntimeDep returns true if this module needs to link the minimal UBSan runtime,
  30. // either because it requires it or because a dependent module which requires it to be linked in this module.
  31. MinimalRuntimeDep() bool
  32. // UbsanRuntimeDep returns true if this module needs to link the full UBSan runtime,
  33. // either because it requires it or because a dependent module which requires it to be linked in this module.
  34. UbsanRuntimeDep() bool
  35. // UbsanRuntimeNeeded returns true if the full UBSan runtime is required by this module.
  36. UbsanRuntimeNeeded() bool
  37. // MinimalRuntimeNeeded returns true if the minimal UBSan runtime is required by this module
  38. MinimalRuntimeNeeded() bool
  39. // SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
  40. SanitizableDepTagChecker() SantizableDependencyTagChecker
  41. }
  42. // SantizableDependencyTagChecker functions check whether or not a dependency
  43. // tag can be sanitized. These functions should return true if the tag can be
  44. // sanitized, otherwise they should return false. These functions should also
  45. // handle all possible dependency tags in the dependency tree. For example,
  46. // Rust modules can depend on both Rust and CC libraries, so the Rust module
  47. // implementation should handle tags from both.
  48. type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
  49. // Snapshottable defines those functions necessary for handling module snapshots.
  50. type Snapshottable interface {
  51. snapshot.VendorSnapshotModuleInterface
  52. snapshot.RecoverySnapshotModuleInterface
  53. // SnapshotHeaders returns a list of header paths provided by this module.
  54. SnapshotHeaders() android.Paths
  55. // SnapshotLibrary returns true if this module is a snapshot library.
  56. IsSnapshotLibrary() bool
  57. // EffectiveLicenseFiles returns the list of License files for this module.
  58. EffectiveLicenseFiles() android.Paths
  59. // SnapshotRuntimeLibs returns a list of libraries needed by this module at runtime but which aren't build dependencies.
  60. SnapshotRuntimeLibs() []string
  61. // SnapshotSharedLibs returns the list of shared library dependencies for this module.
  62. SnapshotSharedLibs() []string
  63. // SnapshotStaticLibs returns the list of static library dependencies for this module.
  64. SnapshotStaticLibs() []string
  65. // IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
  66. IsSnapshotPrebuilt() bool
  67. }
  68. // LinkableInterface is an interface for a type of module that is linkable in a C++ library.
  69. type LinkableInterface interface {
  70. android.Module
  71. Snapshottable
  72. Module() android.Module
  73. CcLibrary() bool
  74. CcLibraryInterface() bool
  75. // RustLibraryInterface returns true if this is a Rust library module
  76. RustLibraryInterface() bool
  77. // BaseModuleName returns the android.ModuleBase.BaseModuleName() value for this module.
  78. BaseModuleName() string
  79. OutputFile() android.OptionalPath
  80. UnstrippedOutputFile() android.Path
  81. CoverageFiles() android.Paths
  82. // CoverageOutputFile returns the output archive of gcno coverage information files.
  83. CoverageOutputFile() android.OptionalPath
  84. NonCcVariants() bool
  85. SelectedStl() string
  86. BuildStaticVariant() bool
  87. BuildSharedVariant() bool
  88. SetStatic()
  89. SetShared()
  90. IsPrebuilt() bool
  91. Toc() android.OptionalPath
  92. // IsFuzzModule returns true if this a *_fuzz module.
  93. IsFuzzModule() bool
  94. // FuzzPackagedModule returns the fuzz.FuzzPackagedModule for this module.
  95. // Expects that IsFuzzModule returns true.
  96. FuzzPackagedModule() fuzz.FuzzPackagedModule
  97. // FuzzSharedLibraries returns the shared library dependencies for this module.
  98. // Expects that IsFuzzModule returns true.
  99. FuzzSharedLibraries() android.RuleBuilderInstalls
  100. Device() bool
  101. Host() bool
  102. InRamdisk() bool
  103. OnlyInRamdisk() bool
  104. InVendorRamdisk() bool
  105. OnlyInVendorRamdisk() bool
  106. InRecovery() bool
  107. OnlyInRecovery() bool
  108. InVendor() bool
  109. UseSdk() bool
  110. // IsNdk returns true if the library is in the configs known NDK list.
  111. IsNdk(config android.Config) bool
  112. // IsStubs returns true if the this is a stubs library.
  113. IsStubs() bool
  114. // IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
  115. IsLlndk() bool
  116. // IsLlndkPublic returns true only for LLNDK (public) libs.
  117. IsLlndkPublic() bool
  118. // HasLlndkStubs returns true if this library has a variant that will build LLNDK stubs.
  119. HasLlndkStubs() bool
  120. // NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
  121. NeedsLlndkVariants() bool
  122. // NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
  123. NeedsVendorPublicLibraryVariants() bool
  124. //StubsVersion returns the stubs version for this module.
  125. StubsVersion() string
  126. // UseVndk returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
  127. // "product" and "vendor" variant modules return true for this function.
  128. // When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
  129. // "soc_specific: true" and more vendor installed modules are included here.
  130. // When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
  131. // "product_specific: true" modules are included here.
  132. UseVndk() bool
  133. // Bootstrap tests if this module is allowed to use non-APEX version of libraries.
  134. Bootstrap() bool
  135. // IsVndkSp returns true if this is a VNDK-SP module.
  136. IsVndkSp() bool
  137. MustUseVendorVariant() bool
  138. IsVndk() bool
  139. IsVndkExt() bool
  140. IsVndkPrivate() bool
  141. IsVendorPublicLibrary() bool
  142. IsVndkPrebuiltLibrary() bool
  143. HasVendorVariant() bool
  144. HasProductVariant() bool
  145. HasNonSystemVariants() bool
  146. ProductSpecific() bool
  147. InProduct() bool
  148. SdkAndPlatformVariantVisibleToMake() bool
  149. // SubName returns the modules SubName, used for image and NDK/SDK variations.
  150. SubName() string
  151. SdkVersion() string
  152. MinSdkVersion() string
  153. AlwaysSdk() bool
  154. IsSdkVariant() bool
  155. SplitPerApiLevel() bool
  156. // SetPreventInstall sets the PreventInstall property to 'true' for this module.
  157. SetPreventInstall()
  158. // SetHideFromMake sets the HideFromMake property to 'true' for this module.
  159. SetHideFromMake()
  160. // KernelHeadersDecorator returns true if this is a kernel headers decorator module.
  161. // This is specific to cc and should always return false for all other packages.
  162. KernelHeadersDecorator() bool
  163. // HiddenFromMake returns true if this module is hidden from Make.
  164. HiddenFromMake() bool
  165. // RelativeInstallPath returns the relative install path for this module.
  166. RelativeInstallPath() string
  167. // Binary returns true if this is a binary module.
  168. Binary() bool
  169. // Object returns true if this is an object module.
  170. Object() bool
  171. // Rlib returns true if this is an rlib module.
  172. Rlib() bool
  173. // Dylib returns true if this is an dylib module.
  174. Dylib() bool
  175. // Static returns true if this is a static library module.
  176. Static() bool
  177. // Shared returns true if this is a shared library module.
  178. Shared() bool
  179. // Header returns true if this is a library headers module.
  180. Header() bool
  181. // StaticExecutable returns true if this is a binary module with "static_executable: true".
  182. StaticExecutable() bool
  183. // EverInstallable returns true if the module is ever installable
  184. EverInstallable() bool
  185. // PreventInstall returns true if this module is prevented from installation.
  186. PreventInstall() bool
  187. // InstallInData returns true if this module is installed in data.
  188. InstallInData() bool
  189. // Installable returns a bool pointer to the module installable property.
  190. Installable() *bool
  191. // Symlinks returns a list of symlinks that should be created for this module.
  192. Symlinks() []string
  193. // VndkVersion returns the VNDK version string for this module.
  194. VndkVersion() string
  195. // Partition returns the partition string for this module.
  196. Partition() string
  197. // FuzzModule returns the fuzz.FuzzModule associated with the module.
  198. FuzzModuleStruct() fuzz.FuzzModule
  199. }
  200. var (
  201. // Dependency tag for crtbegin, an object file responsible for initialization.
  202. CrtBeginDepTag = dependencyTag{name: "crtbegin"}
  203. // Dependency tag for crtend, an object file responsible for program termination.
  204. CrtEndDepTag = dependencyTag{name: "crtend"}
  205. // Dependency tag for coverage library.
  206. CoverageDepTag = dependencyTag{name: "coverage"}
  207. )
  208. // GetImageVariantType returns the ImageVariantType string value for the given module
  209. // (these are defined in cc/image.go).
  210. func GetImageVariantType(c LinkableInterface) ImageVariantType {
  211. if c.Host() {
  212. return hostImageVariant
  213. } else if c.InVendor() {
  214. return vendorImageVariant
  215. } else if c.InProduct() {
  216. return productImageVariant
  217. } else if c.InRamdisk() {
  218. return ramdiskImageVariant
  219. } else if c.InVendorRamdisk() {
  220. return vendorRamdiskImageVariant
  221. } else if c.InRecovery() {
  222. return recoveryImageVariant
  223. } else {
  224. return coreImageVariant
  225. }
  226. }
  227. // DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
  228. // Returns an empty string if not a library dependency tag.
  229. func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
  230. if libDepTag, ok := depTag.(libraryDependencyTag); ok {
  231. return libDepTag.makeSuffix
  232. }
  233. return ""
  234. }
  235. // SharedDepTag returns the dependency tag for any C++ shared libraries.
  236. func SharedDepTag() blueprint.DependencyTag {
  237. return libraryDependencyTag{Kind: sharedLibraryDependency}
  238. }
  239. // StaticDepTag returns the dependency tag for any C++ static libraries.
  240. func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
  241. return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
  242. }
  243. // IsWholeStaticLib whether a dependency tag is a whole static library dependency.
  244. func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
  245. if tag, ok := depTag.(libraryDependencyTag); ok {
  246. return tag.wholeStatic
  247. }
  248. return false
  249. }
  250. // HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
  251. func HeaderDepTag() blueprint.DependencyTag {
  252. return libraryDependencyTag{Kind: headerLibraryDependency}
  253. }
  254. // SharedLibraryInfo is a provider to propagate information about a shared C++ library.
  255. type SharedLibraryInfo struct {
  256. SharedLibrary android.Path
  257. Target android.Target
  258. TableOfContents android.OptionalPath
  259. // should be obtained from static analogue
  260. TransitiveStaticLibrariesForOrdering *android.DepSet[android.Path]
  261. }
  262. var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
  263. // SharedStubLibrary is a struct containing information about a stub shared library.
  264. // Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
  265. // library in another APEX, it must depend on the stub version of that library.
  266. type SharedStubLibrary struct {
  267. // The version of the stub (corresponding to the stable version of the shared library being
  268. // stubbed).
  269. Version string
  270. SharedLibraryInfo SharedLibraryInfo
  271. FlagExporterInfo FlagExporterInfo
  272. }
  273. // SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
  274. // which are dependencies of a library.
  275. // Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
  276. // library in another APEX, it must depend on the stub version of that library.
  277. type SharedLibraryStubsInfo struct {
  278. SharedStubLibraries []SharedStubLibrary
  279. IsLLNDK bool
  280. }
  281. var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{})
  282. // StaticLibraryInfo is a provider to propagate information about a static C++ library.
  283. type StaticLibraryInfo struct {
  284. StaticLibrary android.Path
  285. Objects Objects
  286. ReuseObjects Objects
  287. // A static library may contain prebuilt static libraries included with whole_static_libs
  288. // that won't appear in Objects. They are transitively available in
  289. // WholeStaticLibsFromPrebuilts.
  290. WholeStaticLibsFromPrebuilts android.Paths
  291. // This isn't the actual transitive DepSet, shared library dependencies have been
  292. // converted into static library analogues. It is only used to order the static
  293. // library dependencies that were specified for the current module.
  294. TransitiveStaticLibrariesForOrdering *android.DepSet[android.Path]
  295. }
  296. var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
  297. // HeaderLibraryInfo is a marker provider that identifies a module as a header library.
  298. type HeaderLibraryInfo struct {
  299. }
  300. // HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
  301. var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{})
  302. // FlagExporterInfo is a provider to propagate transitive library information
  303. // pertaining to exported include paths and flags.
  304. type FlagExporterInfo struct {
  305. IncludeDirs android.Paths // Include directories to be included with -I
  306. SystemIncludeDirs android.Paths // System include directories to be included with -isystem
  307. Flags []string // Exported raw flags.
  308. Deps android.Paths
  309. GeneratedHeaders android.Paths
  310. }
  311. var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
  312. // flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
  313. func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
  314. includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
  315. systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
  316. headers := android.PathsForBazelOut(ctx, ccInfo.Headers)
  317. return FlagExporterInfo{
  318. IncludeDirs: android.FirstUniquePaths(includes),
  319. SystemIncludeDirs: android.FirstUniquePaths(systemIncludes),
  320. GeneratedHeaders: headers,
  321. // necessary to ensure generated headers are considered implicit deps of dependent actions
  322. Deps: headers,
  323. }
  324. }