2019-10-19 05:18:45 +08:00
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
2021-04-13 03:42:51 +08:00
|
|
|
"android/soong/bazel/cquery"
|
2020-07-28 12:26:48 +08:00
|
|
|
|
|
|
|
"github.com/google/blueprint"
|
2019-10-19 05:18:45 +08:00
|
|
|
)
|
|
|
|
|
2020-12-15 00:27:52 +08:00
|
|
|
// PlatformSanitizeable is an interface for sanitizing platform modules.
|
|
|
|
type PlatformSanitizeable interface {
|
|
|
|
LinkableInterface
|
|
|
|
|
|
|
|
// SanitizePropDefined returns whether the Sanitizer properties struct for this module is defined.
|
|
|
|
SanitizePropDefined() bool
|
|
|
|
|
|
|
|
// IsDependencyRoot returns whether a module is of a type which cannot be a linkage dependency
|
|
|
|
// of another module. For example, cc_binary and rust_binary represent dependency roots as other
|
|
|
|
// modules cannot have linkage dependencies against these types.
|
|
|
|
IsDependencyRoot() bool
|
|
|
|
|
|
|
|
// IsSanitizerEnabled returns whether a sanitizer is enabled.
|
|
|
|
IsSanitizerEnabled(t SanitizerType) bool
|
|
|
|
|
|
|
|
// IsSanitizerExplicitlyDisabled returns whether a sanitizer has been explicitly disabled (set to false) rather
|
|
|
|
// than left undefined.
|
|
|
|
IsSanitizerExplicitlyDisabled(t SanitizerType) bool
|
|
|
|
|
|
|
|
// SanitizeDep returns the value of the SanitizeDep flag, which is set if a module is a dependency of a
|
|
|
|
// sanitized module.
|
|
|
|
SanitizeDep() bool
|
|
|
|
|
|
|
|
// SetSanitizer enables or disables the specified sanitizer type if it's supported, otherwise this should panic.
|
|
|
|
SetSanitizer(t SanitizerType, b bool)
|
|
|
|
|
|
|
|
// SetSanitizerDep returns true if the module is statically linked.
|
|
|
|
SetSanitizeDep(b bool)
|
|
|
|
|
|
|
|
// StaticallyLinked returns true if the module is statically linked.
|
|
|
|
StaticallyLinked() bool
|
|
|
|
|
|
|
|
// SetInSanitizerDir sets the module installation to the sanitizer directory.
|
|
|
|
SetInSanitizerDir()
|
|
|
|
|
|
|
|
// SanitizeNever returns true if this module should never be sanitized.
|
|
|
|
SanitizeNever() bool
|
|
|
|
|
|
|
|
// SanitizerSupported returns true if a sanitizer type is supported by this modules compiler.
|
|
|
|
SanitizerSupported(t SanitizerType) bool
|
|
|
|
|
|
|
|
// SanitizableDepTagChecker returns a SantizableDependencyTagChecker function type.
|
|
|
|
SanitizableDepTagChecker() SantizableDependencyTagChecker
|
|
|
|
}
|
|
|
|
|
|
|
|
// SantizableDependencyTagChecker functions check whether or not a dependency
|
|
|
|
// tag can be sanitized. These functions should return true if the tag can be
|
|
|
|
// sanitized, otherwise they should return false. These functions should also
|
|
|
|
// handle all possible dependency tags in the dependency tree. For example,
|
|
|
|
// Rust modules can depend on both Rust and CC libraries, so the Rust module
|
|
|
|
// implementation should handle tags from both.
|
|
|
|
type SantizableDependencyTagChecker func(tag blueprint.DependencyTag) bool
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// LinkableInterface is an interface for a type of module that is linkable in a C++ library.
|
2019-10-19 05:18:45 +08:00
|
|
|
type LinkableInterface interface {
|
2020-12-02 22:00:51 +08:00
|
|
|
android.Module
|
|
|
|
|
2019-10-19 05:18:45 +08:00
|
|
|
Module() android.Module
|
|
|
|
CcLibrary() bool
|
|
|
|
CcLibraryInterface() bool
|
|
|
|
|
|
|
|
OutputFile() android.OptionalPath
|
2020-04-09 21:56:02 +08:00
|
|
|
CoverageFiles() android.Paths
|
2019-10-19 05:18:45 +08:00
|
|
|
|
2019-11-22 04:30:50 +08:00
|
|
|
NonCcVariants() bool
|
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
SelectedStl() string
|
2019-10-19 05:18:45 +08:00
|
|
|
|
|
|
|
BuildStaticVariant() bool
|
|
|
|
BuildSharedVariant() bool
|
|
|
|
SetStatic()
|
|
|
|
SetShared()
|
2019-10-19 05:49:46 +08:00
|
|
|
Static() bool
|
|
|
|
Shared() bool
|
2020-12-15 00:27:52 +08:00
|
|
|
Header() bool
|
|
|
|
IsPrebuilt() bool
|
2019-10-19 05:49:46 +08:00
|
|
|
Toc() android.OptionalPath
|
|
|
|
|
2020-04-10 11:57:24 +08:00
|
|
|
Host() bool
|
|
|
|
|
2020-01-22 07:53:22 +08:00
|
|
|
InRamdisk() bool
|
|
|
|
OnlyInRamdisk() bool
|
|
|
|
|
2020-10-22 06:17:56 +08:00
|
|
|
InVendorRamdisk() bool
|
|
|
|
OnlyInVendorRamdisk() bool
|
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
InRecovery() bool
|
|
|
|
OnlyInRecovery() bool
|
|
|
|
|
2020-12-15 00:27:52 +08:00
|
|
|
InVendor() bool
|
|
|
|
|
2020-04-08 00:50:32 +08:00
|
|
|
UseSdk() bool
|
2021-03-31 00:19:36 +08:00
|
|
|
|
|
|
|
// IsLlndk returns true for both LLNDK (public) and LLNDK-private libs.
|
2020-12-17 08:46:01 +08:00
|
|
|
IsLlndk() bool
|
2021-03-31 00:19:36 +08:00
|
|
|
|
|
|
|
// IsLlndkPublic returns true only for LLNDK (public) libs.
|
2020-12-17 08:46:01 +08:00
|
|
|
IsLlndkPublic() bool
|
2021-03-31 00:19:36 +08:00
|
|
|
|
2021-04-27 09:37:44 +08:00
|
|
|
// NeedsLlndkVariants returns true if this module has LLNDK stubs or provides LLNDK headers.
|
|
|
|
NeedsLlndkVariants() bool
|
2021-03-31 00:19:36 +08:00
|
|
|
|
2021-04-28 04:06:04 +08:00
|
|
|
// NeedsVendorPublicLibraryVariants returns true if this module has vendor public library stubs.
|
|
|
|
NeedsVendorPublicLibraryVariants() bool
|
2021-03-31 00:19:36 +08:00
|
|
|
|
|
|
|
UseVndk() bool
|
|
|
|
MustUseVendorVariant() bool
|
2019-10-19 05:49:46 +08:00
|
|
|
IsVndk() bool
|
2020-12-02 22:00:51 +08:00
|
|
|
IsVndkExt() bool
|
2020-12-17 08:46:01 +08:00
|
|
|
IsVndkPrivate() bool
|
2019-10-19 05:49:46 +08:00
|
|
|
HasVendorVariant() bool
|
2021-02-03 18:24:13 +08:00
|
|
|
HasProductVariant() bool
|
|
|
|
HasNonSystemVariants() bool
|
2020-12-02 22:00:51 +08:00
|
|
|
InProduct() bool
|
2019-10-19 05:49:46 +08:00
|
|
|
|
2021-04-03 00:41:32 +08:00
|
|
|
// SubName returns the modules SubName, used for image and NDK/SDK variations.
|
|
|
|
SubName() string
|
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
SdkVersion() string
|
2021-03-19 21:18:04 +08:00
|
|
|
MinSdkVersion() string
|
2020-04-08 00:50:32 +08:00
|
|
|
AlwaysSdk() bool
|
Don't create version variants for SDK variants
When a lib has sdk_version set, an SDK variant and a platform variant
are created by the sdkMutator. Then by the versionMutator, if the
library had 'stubs.versions' property, one or more versioned variants
and one impl variant are created for each of the two (SDK and platform)
variants. As a concrete example,
cc_library {
name: "foo",
sdk_version: "current",
stubs: { versions: ["1", "2"], },
}
would create 6 variants:
1) (sdk: "", version: "")
2) (sdk: "", version: "1")
3) (sdk: "", version: "2")
4) (sdk: "sdk", version: "")
5) (sdk: "sdk", version: "1")
6) (sdk: "sdk", version: "2")
This is somewhat uncessary because the need for the SDK mutator is to
have the platform variant (sdk:"") of a lib where sdk_version is unset,
which actually makes sens for the impl variant (version:""), but not
the versioned variants (version:"1" or version:"2").
This is not only unncessary, but also causes duplicate module
definitions in the Make side when doing an unbundled build. Specifically,
The #1 and #4 above both are emitted to Make and get the same name
"foo".
To fix the problem and not to create unnecessary variants, the versioned
variants are no longer created for the sdk variant. So, foo now has
the following variants only.
1) (sdk: "", version: "") // not emitted to Make (by versionMutator)
2) (sdk: "", version: "1") // not emitted to Make (by versionMutator)
3) (sdk: "", version: "2") // emitted to Make (by versionMutator)
4) (sdk: "sdk", version: "") // not emitted to Make (by versionMutator)
Bug: 159106705
Test: Add sdk_version:"minimum" to libnativehelper in libnativehelper/Android.bp.
m SOONG_ALLOW_MISSING_DEPENDENCIES=true TARGET_BUILD_UNBUNDLED=true libnativehelper
Change-Id: I6f02f4189e5504286174ccff1642166da82d00c9
2020-06-16 20:58:53 +08:00
|
|
|
IsSdkVariant() bool
|
2019-10-19 05:49:46 +08:00
|
|
|
|
2020-10-02 04:37:16 +08:00
|
|
|
SplitPerApiLevel() bool
|
2020-12-15 00:27:52 +08:00
|
|
|
|
|
|
|
// SetPreventInstall sets the PreventInstall property to 'true' for this module.
|
|
|
|
SetPreventInstall()
|
|
|
|
// SetHideFromMake sets the HideFromMake property to 'true' for this module.
|
|
|
|
SetHideFromMake()
|
2021-03-31 00:19:36 +08:00
|
|
|
|
|
|
|
// KernelHeadersDecorator returns true if this is a kernel headers decorator module.
|
|
|
|
// This is specific to cc and should always return false for all other packages.
|
|
|
|
KernelHeadersDecorator() bool
|
2019-10-19 05:18:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2020-11-21 01:42:07 +08:00
|
|
|
// Dependency tag for crtbegin, an object file responsible for initialization.
|
2020-07-28 12:26:48 +08:00
|
|
|
CrtBeginDepTag = dependencyTag{name: "crtbegin"}
|
2020-11-21 01:42:07 +08:00
|
|
|
// Dependency tag for crtend, an object file responsible for program termination.
|
|
|
|
CrtEndDepTag = dependencyTag{name: "crtend"}
|
|
|
|
// Dependency tag for coverage library.
|
2020-07-28 12:26:48 +08:00
|
|
|
CoverageDepTag = dependencyTag{name: "coverage"}
|
|
|
|
)
|
2019-10-19 05:18:45 +08:00
|
|
|
|
2020-12-15 00:27:52 +08:00
|
|
|
// GetImageVariantType returns the ImageVariantType string value for the given module
|
|
|
|
// (these are defined in cc/image.go).
|
|
|
|
func GetImageVariantType(c LinkableInterface) ImageVariantType {
|
|
|
|
if c.Host() {
|
|
|
|
return hostImageVariant
|
|
|
|
} else if c.InVendor() {
|
|
|
|
return vendorImageVariant
|
|
|
|
} else if c.InProduct() {
|
|
|
|
return productImageVariant
|
|
|
|
} else if c.InRamdisk() {
|
|
|
|
return ramdiskImageVariant
|
|
|
|
} else if c.InVendorRamdisk() {
|
|
|
|
return vendorRamdiskImageVariant
|
|
|
|
} else if c.InRecovery() {
|
|
|
|
return recoveryImageVariant
|
|
|
|
} else {
|
|
|
|
return coreImageVariant
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-03 00:41:32 +08:00
|
|
|
// DepTagMakeSuffix returns the makeSuffix value of a particular library dependency tag.
|
|
|
|
// Returns an empty string if not a library dependency tag.
|
|
|
|
func DepTagMakeSuffix(depTag blueprint.DependencyTag) string {
|
|
|
|
if libDepTag, ok := depTag.(libraryDependencyTag); ok {
|
|
|
|
return libDepTag.makeSuffix
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// SharedDepTag returns the dependency tag for any C++ shared libraries.
|
2020-07-28 12:26:48 +08:00
|
|
|
func SharedDepTag() blueprint.DependencyTag {
|
|
|
|
return libraryDependencyTag{Kind: sharedLibraryDependency}
|
|
|
|
}
|
shared_lib dependency from a static lib crosses the APEX boundary
cc_library_static {
name: "libfoo",
shared_libs: ["libbar"],
}
cc_library {
name: "libbar",
}
If libfoo is part of an APEX, then libbar is no longer considered as a
member of the APEX, because it isn't actually linked to libfoo.
To distinguish such a shared lib dependency from a static library from a
shared lib dependency from a shared library, a new dep type
SharedFromStaticDepTag is introduced. It is treated exactly the same as
SharedDepTag, except when we determine whether a dependency is crossing
the APEX boundary or not.
This allows us to check the apex_available property more correctly.
Previously, modules were incorrectly considered as being used for an
APEX due to the shared lib dependency from a static lib.
As a good side effect, this also reduces the number of APEX variants.
Specifically, on aosp_arm64, the number of the generated modules were
reduced from 44745 to 44180.
Exempt-From-Owner-Approval: cherry-pick from internal
Bug: 147671264
Test: m
Merged-In: I899ccb9eae1574effef77ca1bc3a0df145983861
(cherry picked from commit 931b676a69c092451ed25a5dda67accf90ce6457)
Change-Id: I899ccb9eae1574effef77ca1bc3a0df145983861
2020-01-16 16:14:23 +08:00
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// StaticDepTag returns the dependency tag for any C++ static libraries.
|
2021-03-24 03:53:44 +08:00
|
|
|
func StaticDepTag(wholeStatic bool) blueprint.DependencyTag {
|
|
|
|
return libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: wholeStatic}
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsWholeStaticLib whether a dependency tag is a whole static library dependency.
|
|
|
|
func IsWholeStaticLib(depTag blueprint.DependencyTag) bool {
|
|
|
|
if tag, ok := depTag.(libraryDependencyTag); ok {
|
|
|
|
return tag.wholeStatic
|
|
|
|
}
|
|
|
|
return false
|
2020-07-28 12:26:48 +08:00
|
|
|
}
|
2020-09-19 05:15:30 +08:00
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// HeaderDepTag returns the dependency tag for any C++ "header-only" libraries.
|
2020-11-07 03:56:27 +08:00
|
|
|
func HeaderDepTag() blueprint.DependencyTag {
|
|
|
|
return libraryDependencyTag{Kind: headerLibraryDependency}
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// SharedLibraryInfo is a provider to propagate information about a shared C++ library.
|
2020-09-19 05:15:30 +08:00
|
|
|
type SharedLibraryInfo struct {
|
|
|
|
SharedLibrary android.Path
|
|
|
|
UnstrippedSharedLibrary android.Path
|
2021-01-27 03:00:18 +08:00
|
|
|
Target android.Target
|
2020-09-19 05:15:30 +08:00
|
|
|
|
|
|
|
TableOfContents android.OptionalPath
|
|
|
|
CoverageSharedLibrary android.OptionalPath
|
|
|
|
|
|
|
|
StaticAnalogue *StaticLibraryInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{})
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// SharedStubLibrary is a struct containing information about a stub shared library.
|
|
|
|
// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
|
|
|
|
// library in another APEX, it must depend on the stub version of that library.
|
|
|
|
type SharedStubLibrary struct {
|
|
|
|
// The version of the stub (corresponding to the stable version of the shared library being
|
|
|
|
// stubbed).
|
2020-09-19 05:15:30 +08:00
|
|
|
Version string
|
|
|
|
SharedLibraryInfo SharedLibraryInfo
|
|
|
|
FlagExporterInfo FlagExporterInfo
|
|
|
|
}
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// SharedLibraryStubsInfo is a provider to propagate information about all shared library stubs
|
|
|
|
// which are dependencies of a library.
|
|
|
|
// Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared
|
|
|
|
// library in another APEX, it must depend on the stub version of that library.
|
|
|
|
type SharedLibraryStubsInfo struct {
|
|
|
|
SharedStubLibraries []SharedStubLibrary
|
|
|
|
|
|
|
|
IsLLNDK bool
|
|
|
|
}
|
|
|
|
|
|
|
|
var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{})
|
2020-09-19 05:15:30 +08:00
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// StaticLibraryInfo is a provider to propagate information about a static C++ library.
|
2020-09-19 05:15:30 +08:00
|
|
|
type StaticLibraryInfo struct {
|
|
|
|
StaticLibrary android.Path
|
|
|
|
Objects Objects
|
|
|
|
ReuseObjects Objects
|
|
|
|
|
|
|
|
// This isn't the actual transitive DepSet, shared library dependencies have been
|
|
|
|
// converted into static library analogues. It is only used to order the static
|
|
|
|
// library dependencies that were specified for the current module.
|
|
|
|
TransitiveStaticLibrariesForOrdering *android.DepSet
|
|
|
|
}
|
|
|
|
|
|
|
|
var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{})
|
|
|
|
|
2020-12-11 04:30:21 +08:00
|
|
|
// HeaderLibraryInfo is a marker provider that identifies a module as a header library.
|
|
|
|
type HeaderLibraryInfo struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library.
|
|
|
|
var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{})
|
|
|
|
|
2020-11-21 01:42:07 +08:00
|
|
|
// FlagExporterInfo is a provider to propagate transitive library information
|
|
|
|
// pertaining to exported include paths and flags.
|
2020-09-19 05:15:30 +08:00
|
|
|
type FlagExporterInfo struct {
|
2020-11-21 01:42:07 +08:00
|
|
|
IncludeDirs android.Paths // Include directories to be included with -I
|
|
|
|
SystemIncludeDirs android.Paths // System include directories to be included with -isystem
|
|
|
|
Flags []string // Exported raw flags.
|
2020-09-19 05:15:30 +08:00
|
|
|
Deps android.Paths
|
|
|
|
GeneratedHeaders android.Paths
|
|
|
|
}
|
|
|
|
|
|
|
|
var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
|
2021-04-13 03:42:51 +08:00
|
|
|
|
|
|
|
// flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
|
|
|
|
func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
|
|
|
|
|
|
|
|
includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
|
|
|
|
systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
|
|
|
|
|
|
|
|
return FlagExporterInfo{
|
2021-04-28 02:48:30 +08:00
|
|
|
IncludeDirs: android.FirstUniquePaths(includes),
|
|
|
|
SystemIncludeDirs: android.FirstUniquePaths(systemIncludes),
|
2021-04-13 03:42:51 +08:00
|
|
|
}
|
|
|
|
}
|