Merge "Reland "Update clang version to clang-r475365""
diff --git a/cc/androidmk.go b/cc/androidmk.go
index 58bb57c..aaf21e9 100644
--- a/cc/androidmk.go
+++ b/cc/androidmk.go
@@ -227,27 +227,17 @@
}
}
-func (library *libraryDecorator) getAbiDiffsForAndroidMkDeps() []string {
- if library.static() {
- return nil
- }
- var abiDiffs []string
- if library.sAbiDiff.Valid() {
- abiDiffs = append(abiDiffs, library.sAbiDiff.String())
- }
- if library.prevSAbiDiff.Valid() {
- abiDiffs = append(abiDiffs, library.prevSAbiDiff.String())
- }
- return abiDiffs
-}
-
func (library *libraryDecorator) androidMkEntriesWriteAdditionalDependenciesForSourceAbiDiff(entries *android.AndroidMkEntries) {
- entries.AddStrings("LOCAL_ADDITIONAL_DEPENDENCIES", library.getAbiDiffsForAndroidMkDeps()...)
+ if !library.static() {
+ entries.AddPaths("LOCAL_ADDITIONAL_DEPENDENCIES", library.sAbiDiff)
+ }
}
// TODO(ccross): remove this once apex/androidmk.go is converted to AndroidMkEntries
func (library *libraryDecorator) androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
- fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES +=", strings.Join(library.getAbiDiffsForAndroidMkDeps(), " "))
+ if !library.static() {
+ fmt.Fprintln(w, "LOCAL_ADDITIONAL_DEPENDENCIES +=", strings.Join(library.sAbiDiff.Strings(), " "))
+ }
}
func (library *libraryDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
diff --git a/cc/builder.go b/cc/builder.go
index 46cea0b..cf20923 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -923,47 +923,17 @@
return outputFile
}
-// sourceAbiDiff registers a build statement to compare linked sAbi dump files (.lsdump).
-func sourceAbiDiff(ctx android.ModuleContext, inputDump, referenceDump android.Path,
- baseName string, diffFlags []string, prevVersion int,
- checkAllApis, isLlndkOrNdk, isVndkExt, previousVersionDiff bool) android.OptionalPath {
+func transformAbiDumpToAbiDiff(ctx android.ModuleContext, inputDump, referenceDump android.Path,
+ baseName, nameExt string, extraFlags []string, errorMessage string) android.Path {
var outputFile android.ModuleOutPath
- if previousVersionDiff {
- outputFile = android.PathForModuleOut(ctx, baseName+"."+strconv.Itoa(prevVersion)+".abidiff")
+ if nameExt != "" {
+ outputFile = android.PathForModuleOut(ctx, baseName+"."+nameExt+".abidiff")
} else {
outputFile = android.PathForModuleOut(ctx, baseName+".abidiff")
}
libName := strings.TrimSuffix(baseName, filepath.Ext(baseName))
- var extraFlags []string
- if checkAllApis {
- extraFlags = append(extraFlags, "-check-all-apis")
- } else {
- extraFlags = append(extraFlags,
- "-allow-unreferenced-changes",
- "-allow-unreferenced-elf-symbol-changes")
- }
-
- var errorMessage string
- if previousVersionDiff {
- errorMessage = "error: Please follow https://android.googlesource.com/platform/development/+/master/vndk/tools/header-checker/README.md#configure-cross_version-abi-check to resolve the ABI difference between your source code and version " + strconv.Itoa(prevVersion) + "."
- sourceVersion := prevVersion + 1
- extraFlags = append(extraFlags, "-target-version", strconv.Itoa(sourceVersion))
- } else {
- errorMessage = "error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py -l " + libName
- extraFlags = append(extraFlags, "-target-version", "current")
- }
-
- if isLlndkOrNdk {
- extraFlags = append(extraFlags, "-consider-opaque-types-different")
- }
- if isVndkExt || previousVersionDiff {
- extraFlags = append(extraFlags, "-allow-extensions")
- }
- // TODO(b/232891473): Simplify the above logic with diffFlags.
- extraFlags = append(extraFlags, diffFlags...)
-
ctx.Build(pctx, android.BuildParams{
Rule: sAbiDiff,
Description: "header-abi-diff " + outputFile.Base(),
@@ -978,7 +948,7 @@
"errorMessage": errorMessage,
},
})
- return android.OptionalPathForPath(outputFile)
+ return outputFile
}
// Generate a rule for extracting a table of contents from a shared library (.so)
diff --git a/cc/cc.go b/cc/cc.go
index 8b3f456..2ff5bba 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -2314,28 +2314,23 @@
return nonvariantLibs, variantLibs
}
-func updateDepsWithApiImports(deps Deps, apiImports multitree.ApiImportInfo) Deps {
- for idx, lib := range deps.SharedLibs {
- deps.SharedLibs[idx] = GetReplaceModuleName(lib, apiImports.SharedLibs)
+func rewriteLibsForApiImports(c LinkableInterface, libs []string, replaceList map[string]string, config android.Config) ([]string, []string) {
+ nonVariantLibs := []string{}
+ variantLibs := []string{}
+
+ for _, lib := range libs {
+ replaceLibName := GetReplaceModuleName(lib, replaceList)
+ if replaceLibName == lib {
+ // Do not handle any libs which are not in API imports
+ nonVariantLibs = append(nonVariantLibs, replaceLibName)
+ } else if c.UseSdk() && inList(replaceLibName, *getNDKKnownLibs(config)) {
+ variantLibs = append(variantLibs, replaceLibName)
+ } else {
+ nonVariantLibs = append(nonVariantLibs, replaceLibName)
+ }
}
- for idx, lib := range deps.LateSharedLibs {
- deps.LateSharedLibs[idx] = GetReplaceModuleName(lib, apiImports.SharedLibs)
- }
-
- for idx, lib := range deps.RuntimeLibs {
- deps.RuntimeLibs[idx] = GetReplaceModuleName(lib, apiImports.SharedLibs)
- }
-
- for idx, lib := range deps.SystemSharedLibs {
- deps.SystemSharedLibs[idx] = GetReplaceModuleName(lib, apiImports.SharedLibs)
- }
-
- for idx, lib := range deps.ReexportSharedLibHeaders {
- deps.ReexportSharedLibHeaders[idx] = GetReplaceModuleName(lib, apiImports.SharedLibs)
- }
-
- return deps
+ return nonVariantLibs, variantLibs
}
func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
@@ -2354,8 +2349,15 @@
deps := c.deps(ctx)
apiImportInfo := GetApiImports(c, actx)
+ apiNdkLibs := []string{}
+ apiLateNdkLibs := []string{}
+
if ctx.Os() == android.Android && c.Target().NativeBridge != android.NativeBridgeEnabled {
- deps = updateDepsWithApiImports(deps, apiImportInfo)
+ deps.SharedLibs, apiNdkLibs = rewriteLibsForApiImports(c, deps.SharedLibs, apiImportInfo.SharedLibs, ctx.Config())
+ deps.LateSharedLibs, apiLateNdkLibs = rewriteLibsForApiImports(c, deps.LateSharedLibs, apiImportInfo.SharedLibs, ctx.Config())
+ deps.SystemSharedLibs, _ = rewriteLibsForApiImports(c, deps.SystemSharedLibs, apiImportInfo.SharedLibs, ctx.Config())
+ deps.ReexportHeaderLibHeaders, _ = rewriteLibsForApiImports(c, deps.ReexportHeaderLibHeaders, apiImportInfo.SharedLibs, ctx.Config())
+ deps.ReexportSharedLibHeaders, _ = rewriteLibsForApiImports(c, deps.ReexportSharedLibHeaders, apiImportInfo.SharedLibs, ctx.Config())
}
c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
@@ -2542,12 +2544,20 @@
{Mutator: "version", Variation: version},
{Mutator: "link", Variation: "shared"},
}, ndkStubDepTag, variantNdkLibs...)
+ actx.AddVariationDependencies([]blueprint.Variation{
+ {Mutator: "version", Variation: version},
+ {Mutator: "link", Variation: "shared"},
+ }, ndkStubDepTag, apiNdkLibs...)
ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
actx.AddVariationDependencies([]blueprint.Variation{
{Mutator: "version", Variation: version},
{Mutator: "link", Variation: "shared"},
}, ndkLateStubDepTag, variantLateNdkLibs...)
+ actx.AddVariationDependencies([]blueprint.Variation{
+ {Mutator: "version", Variation: version},
+ {Mutator: "link", Variation: "shared"},
+ }, ndkLateStubDepTag, apiLateNdkLibs...)
if vndkdep := c.vndkdep; vndkdep != nil {
if vndkdep.isVndkExt() {
@@ -2601,6 +2611,10 @@
}
return
}
+ // TODO(b/244244438) : Remove this once all variants are implemented
+ if ccFrom, ok := from.(*Module); ok && ccFrom.isImportedApiLibrary() {
+ return
+ }
if from.SdkVersion() == "" {
// Platform code can link to anything
return
@@ -2627,6 +2641,10 @@
// the NDK.
return
}
+ if c.isImportedApiLibrary() {
+ // Imported library from the API surface is a stub library built against interface definition.
+ return
+ }
}
if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
diff --git a/cc/config/global.go b/cc/config/global.go
index a26a777..61151d1 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -222,7 +222,6 @@
// http://b/145211066
"-Wno-implicit-int-float-conversion",
// New warnings to be fixed after clang-r377782.
- "-Wno-sizeof-array-div", // http://b/148815709
"-Wno-tautological-overlap-compare", // http://b/148815696
// New warnings to be fixed after clang-r383902.
"-Wno-deprecated-copy", // http://b/153746672
@@ -249,6 +248,8 @@
}
noOverrideExternalGlobalCflags = []string{
+ // http://b/148815709
+ "-Wno-sizeof-array-div",
// http://b/197240255
"-Wno-unused-but-set-variable",
"-Wno-unused-but-set-parameter",
diff --git a/cc/library.go b/cc/library.go
index 673f1ca..ff16ff5 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -804,10 +804,7 @@
sAbiOutputFile android.OptionalPath
// Source Abi Diff
- sAbiDiff android.OptionalPath
-
- // Source Abi Diff against previous SDK version
- prevSAbiDiff android.OptionalPath
+ sAbiDiff android.Paths
// Location of the static library in the sysroot. Empty if the library is
// not included in the NDK.
@@ -1797,10 +1794,10 @@
return library.coverageOutputFile
}
-// pathForVndkRefAbiDump returns an OptionalPath representing the path of the
+// pathForRefAbiDump returns an OptionalPath representing the path of the
// reference abi dump for the given module. This is not guaranteed to be valid.
-func pathForVndkRefAbiDump(ctx android.ModuleInstallPathContext, version, fileName string,
- isNdk, isVndk, isGzip bool) android.OptionalPath {
+func pathForRefAbiDump(ctx android.ModuleInstallPathContext,
+ versionedDumpDir, fileName string, isGzip bool) android.OptionalPath {
currentArchType := ctx.Arch().ArchType
primaryArchType := ctx.Config().DevicePrimaryArchType()
@@ -1809,17 +1806,6 @@
archName += "_" + primaryArchType.String()
}
- var dirName string
- if isNdk {
- dirName = "ndk"
- } else if isVndk {
- dirName = "vndk"
- } else {
- dirName = "platform" // opt-in libs
- }
-
- binderBitness := ctx.DeviceConfig().BinderBitness()
-
var ext string
if isGzip {
ext = ".lsdump.gz"
@@ -1827,18 +1813,25 @@
ext = ".lsdump"
}
- return android.ExistentPathForSource(ctx, "prebuilts", "abi-dumps", dirName,
- version, binderBitness, archName, "source-based",
+ return android.ExistentPathForSource(ctx, versionedDumpDir, archName, "source-based",
fileName+ext)
}
-func getRefAbiDumpFile(ctx ModuleContext, vndkVersion, fileName string) android.Path {
- // The logic must be consistent with classifySourceAbiDump.
- isNdk := ctx.isNdk(ctx.Config())
- isVndk := ctx.useVndk() && ctx.isVndk()
+func getRefAbiDumpDir(isNdk, isVndk bool) string {
+ var dirName string
+ if isNdk {
+ dirName = "ndk"
+ } else if isVndk {
+ dirName = "vndk"
+ } else {
+ dirName = "platform"
+ }
+ return filepath.Join("prebuilts", "abi-dumps", dirName)
+}
- refAbiDumpTextFile := pathForVndkRefAbiDump(ctx, vndkVersion, fileName, isNdk, isVndk, false)
- refAbiDumpGzipFile := pathForVndkRefAbiDump(ctx, vndkVersion, fileName, isNdk, isVndk, true)
+func getRefAbiDumpFile(ctx ModuleContext, versionedDumpDir, fileName string) android.Path {
+ refAbiDumpTextFile := pathForRefAbiDump(ctx, versionedDumpDir, fileName, /* isGzip */ false)
+ refAbiDumpGzipFile := pathForRefAbiDump(ctx, versionedDumpDir, fileName, /* isGzip */ true)
if refAbiDumpTextFile.Valid() {
if refAbiDumpGzipFile.Valid() {
@@ -1855,27 +1848,18 @@
return nil
}
-func prevDumpRefVersion(ctx ModuleContext) int {
+func prevRefAbiDumpVersion(ctx ModuleContext, dumpDir string) int {
sdkVersionInt := ctx.Config().PlatformSdkVersion().FinalInt()
sdkVersionStr := ctx.Config().PlatformSdkVersion().String()
if ctx.Config().PlatformSdkFinal() {
return sdkVersionInt - 1
} else {
- var dirName string
-
- isNdk := ctx.isNdk(ctx.Config())
- if isNdk {
- dirName = "ndk"
- } else {
- dirName = "platform"
- }
-
// The platform SDK version can be upgraded before finalization while the corresponding abi dumps hasn't
// been generated. Thus the Cross-Version Check chooses PLATFORM_SDK_VERION - 1 as previous version.
// This situation could be identified by checking the existence of the PLATFORM_SDK_VERION dump directory.
- refDumpDir := android.ExistentPathForSource(ctx, "prebuilts", "abi-dumps", dirName, sdkVersionStr)
- if refDumpDir.Valid() {
+ versionedDumpDir := android.ExistentPathForSource(ctx, dumpDir, sdkVersionStr)
+ if versionedDumpDir.Valid() {
return sdkVersionInt
} else {
return sdkVersionInt - 1
@@ -1896,6 +1880,54 @@
}
}
+// sourceAbiDiff registers a build statement to compare linked sAbi dump files (.lsdump).
+func (library *libraryDecorator) sourceAbiDiff(ctx android.ModuleContext, referenceDump android.Path,
+ baseName, nameExt string, isLlndkOrNdk, allowExtensions bool,
+ sourceVersion, errorMessage string) {
+
+ sourceDump := library.sAbiOutputFile.Path()
+
+ extraFlags := []string{"-target-version", sourceVersion}
+ if Bool(library.Properties.Header_abi_checker.Check_all_apis) {
+ extraFlags = append(extraFlags, "-check-all-apis")
+ } else {
+ extraFlags = append(extraFlags,
+ "-allow-unreferenced-changes",
+ "-allow-unreferenced-elf-symbol-changes")
+ }
+ if isLlndkOrNdk {
+ extraFlags = append(extraFlags, "-consider-opaque-types-different")
+ }
+ if allowExtensions {
+ extraFlags = append(extraFlags, "-allow-extensions")
+ }
+ extraFlags = append(extraFlags, library.Properties.Header_abi_checker.Diff_flags...)
+
+ library.sAbiDiff = append(
+ library.sAbiDiff,
+ transformAbiDumpToAbiDiff(ctx, sourceDump, referenceDump,
+ baseName, nameExt, extraFlags, errorMessage))
+}
+
+func (library *libraryDecorator) crossVersionAbiDiff(ctx android.ModuleContext, referenceDump android.Path,
+ baseName string, isLlndkOrNdk bool, sourceVersion, prevVersion string) {
+
+ errorMessage := "error: Please follow https://android.googlesource.com/platform/development/+/master/vndk/tools/header-checker/README.md#configure-cross_version-abi-check to resolve the ABI difference between your source code and version " + prevVersion + "."
+
+ library.sourceAbiDiff(ctx, referenceDump, baseName, prevVersion,
+ isLlndkOrNdk, /* allowExtensions */ true, sourceVersion, errorMessage)
+}
+
+func (library *libraryDecorator) sameVersionAbiDiff(ctx android.ModuleContext, referenceDump android.Path,
+ baseName string, isLlndkOrNdk, allowExtensions bool) {
+
+ libName := strings.TrimSuffix(baseName, filepath.Ext(baseName))
+ errorMessage := "error: Please update ABI references with: $$ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py -l " + libName
+
+ library.sourceAbiDiff(ctx, referenceDump, baseName, /* nameExt */ "",
+ isLlndkOrNdk, allowExtensions, "current", errorMessage)
+}
+
func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string, soFile android.Path) {
if library.sabi.shouldCreateSourceAbiDump() {
exportIncludeDirs := library.flagExporter.exportedIncludes(ctx)
@@ -1914,31 +1946,31 @@
addLsdumpPath(classifySourceAbiDump(ctx) + ":" + library.sAbiOutputFile.String())
+ // The logic must be consistent with classifySourceAbiDump.
isVndk := ctx.useVndk() && ctx.isVndk()
isNdk := ctx.isNdk(ctx.Config())
isLlndk := ctx.isImplementationForLLNDKPublic()
+ dumpDir := getRefAbiDumpDir(isNdk, isVndk)
+ binderBitness := ctx.DeviceConfig().BinderBitness()
// If NDK or PLATFORM library, check against previous version ABI.
if !isVndk {
- prevVersion := prevDumpRefVersion(ctx)
- prevRefAbiDumpFile := getRefAbiDumpFile(ctx, strconv.Itoa(prevVersion), fileName)
- if prevRefAbiDumpFile != nil {
- library.prevSAbiDiff = sourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
- prevRefAbiDumpFile, fileName,
- library.Properties.Header_abi_checker.Diff_flags, prevVersion,
- Bool(library.Properties.Header_abi_checker.Check_all_apis),
- isLlndk || isNdk, ctx.IsVndkExt(), true)
+ prevVersionInt := prevRefAbiDumpVersion(ctx, dumpDir)
+ prevVersion := strconv.Itoa(prevVersionInt)
+ prevDumpDir := filepath.Join(dumpDir, prevVersion, binderBitness)
+ prevDumpFile := getRefAbiDumpFile(ctx, prevDumpDir, fileName)
+ if prevDumpFile != nil {
+ library.crossVersionAbiDiff(ctx, prevDumpFile,
+ fileName, isLlndk || isNdk,
+ strconv.Itoa(prevVersionInt+1), prevVersion)
}
}
-
+ // Check against the current version.
currVersion := currRefAbiDumpVersion(ctx, isVndk)
- refAbiDumpFile := getRefAbiDumpFile(ctx, currVersion, fileName)
- if refAbiDumpFile != nil {
- library.sAbiDiff = sourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
- refAbiDumpFile, fileName,
- library.Properties.Header_abi_checker.Diff_flags,
- /* unused if not previousVersionDiff */ 0,
- Bool(library.Properties.Header_abi_checker.Check_all_apis),
- isLlndk || isNdk, ctx.IsVndkExt(), false)
+ currDumpDir := filepath.Join(dumpDir, currVersion, binderBitness)
+ currDumpFile := getRefAbiDumpFile(ctx, currDumpDir, fileName)
+ if currDumpFile != nil {
+ library.sameVersionAbiDiff(ctx, currDumpFile,
+ fileName, isLlndk || isNdk, ctx.IsVndkExt())
}
}
}
diff --git a/cc/library_stub.go b/cc/library_stub.go
index 043c03c..22e61a7 100644
--- a/cc/library_stub.go
+++ b/cc/library_stub.go
@@ -15,14 +15,17 @@
package cc
import (
+ "regexp"
"strings"
- "github.com/google/blueprint/proptools"
-
"android/soong/android"
"android/soong/multitree"
)
+var (
+ ndkVariantRegex = regexp.MustCompile("ndk\\.([a-zA-Z0-9]+)")
+)
+
func init() {
RegisterLibraryStubBuildComponents(android.InitRegistrationContext)
}
@@ -45,13 +48,17 @@
}
if m.UseVndk() && apiLibrary.hasLLNDKStubs() {
- // Add LLNDK dependencies
- for _, variant := range apiLibrary.properties.Variants {
- if variant == "llndk" {
- variantName := BuildApiVariantName(m.BaseModuleName(), "llndk", "")
- ctx.AddDependency(m, nil, variantName)
- break
- }
+ // Add LLNDK variant dependency
+ if inList("llndk", apiLibrary.properties.Variants) {
+ variantName := BuildApiVariantName(m.BaseModuleName(), "llndk", "")
+ ctx.AddDependency(m, nil, variantName)
+ }
+ } else if m.IsSdkVariant() {
+ // Add NDK variant dependencies
+ targetVariant := "ndk." + m.StubsVersion()
+ if inList(targetVariant, apiLibrary.properties.Variants) {
+ variantName := BuildApiVariantName(m.BaseModuleName(), targetVariant, "")
+ ctx.AddDependency(m, nil, variantName)
}
}
}
@@ -117,12 +124,31 @@
}
}
+func (d *apiLibraryDecorator) linkerInit(ctx BaseModuleContext) {
+ d.baseLinker.linkerInit(ctx)
+
+ if d.hasNDKStubs() {
+ // Set SDK version of module as current
+ ctx.Module().(*Module).Properties.Sdk_version = StringPtr("current")
+
+ // Add NDK stub as NDK known libs
+ name := ctx.ModuleName()
+
+ ndkKnownLibsLock.Lock()
+ ndkKnownLibs := getNDKKnownLibs(ctx.Config())
+ if !inList(name, *ndkKnownLibs) {
+ *ndkKnownLibs = append(*ndkKnownLibs, name)
+ }
+ ndkKnownLibsLock.Unlock()
+ }
+}
+
func (d *apiLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objects Objects) android.Path {
m, _ := ctx.Module().(*Module)
var in android.Path
- if src := proptools.String(d.properties.Src); src != "" {
+ if src := String(d.properties.Src); src != "" {
in = android.PathForModuleSrc(ctx, src)
}
@@ -149,7 +175,7 @@
variantMod.exportProperties.Export_headers...)
// Export headers as system include dirs if specified. Mostly for libc
- if proptools.Bool(variantMod.exportProperties.Export_headers_as_system) {
+ if Bool(variantMod.exportProperties.Export_headers_as_system) {
d.libraryDecorator.flagExporter.Properties.Export_system_include_dirs = append(
d.libraryDecorator.flagExporter.Properties.Export_system_include_dirs,
d.libraryDecorator.flagExporter.Properties.Export_include_dirs...)
@@ -157,6 +183,29 @@
}
}
}
+ } else if m.IsSdkVariant() {
+ // NDK Variant
+ apiVariantModule := BuildApiVariantName(m.BaseModuleName(), "ndk", m.StubsVersion())
+
+ var mod android.Module
+
+ ctx.VisitDirectDeps(func(depMod android.Module) {
+ if depMod.Name() == apiVariantModule {
+ mod = depMod
+ }
+ })
+
+ if mod != nil {
+ variantMod, ok := mod.(*CcApiVariant)
+ if ok {
+ in = variantMod.Src()
+
+ // Copy NDK properties to cc_api_library module
+ d.libraryDecorator.flagExporter.Properties.Export_include_dirs = append(
+ d.libraryDecorator.flagExporter.Properties.Export_include_dirs,
+ variantMod.exportProperties.Export_headers...)
+ }
+ }
}
// Flags reexported from dependencies. (e.g. vndk_prebuilt_shared)
@@ -214,6 +263,14 @@
// TODO(b/244244438) Create more version information for NDK and APEX variations
// NDK variants
+
+ if m.IsSdkVariant() {
+ // TODO(b/249193999) Do not check if module has NDK stubs once all NDK cc_api_library contains ndk variant of cc_api_variant.
+ if d.hasNDKStubs() {
+ return d.getNdkVersions()
+ }
+ }
+
if m.MinSdkVersion() == "" {
return nil
}
@@ -229,14 +286,30 @@
}
func (d *apiLibraryDecorator) hasLLNDKStubs() bool {
+ return inList("llndk", d.properties.Variants)
+}
+
+func (d *apiLibraryDecorator) hasNDKStubs() bool {
for _, variant := range d.properties.Variants {
- if strings.Contains(variant, "llndk") {
+ if ndkVariantRegex.MatchString(variant) {
return true
}
}
return false
}
+func (d *apiLibraryDecorator) getNdkVersions() []string {
+ ndkVersions := []string{}
+
+ for _, variant := range d.properties.Variants {
+ if match := ndkVariantRegex.FindStringSubmatch(variant); len(match) == 2 {
+ ndkVersions = append(ndkVersions, match[1])
+ }
+ }
+
+ return ndkVersions
+}
+
// 'cc_api_headers' is similar with 'cc_api_library', but which replaces
// header libraries. The module will replace any dependencies to existing
// original header libraries.
@@ -320,18 +393,18 @@
func (v *CcApiVariant) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// No need to build
- if proptools.String(v.properties.Src) == "" {
+ if String(v.properties.Src) == "" {
ctx.PropertyErrorf("src", "src is a required property")
}
// Skip the existence check of the stub prebuilt file.
// The file is not guaranteed to exist during Soong analysis.
// Build orchestrator will be responsible for creating a connected ninja graph.
- v.src = android.MaybeExistentPathForSource(ctx, ctx.ModuleDir(), proptools.String(v.properties.Src))
+ v.src = android.MaybeExistentPathForSource(ctx, ctx.ModuleDir(), String(v.properties.Src))
}
func (v *CcApiVariant) Name() string {
- version := proptools.String(v.properties.Version)
+ version := String(v.properties.Version)
return BuildApiVariantName(v.BaseModuleName(), *v.properties.Variant, version)
}
@@ -349,8 +422,10 @@
}
// Implement ImageInterface to generate image variants
-func (v *CcApiVariant) ImageMutatorBegin(ctx android.BaseModuleContext) {}
-func (v *CcApiVariant) CoreVariantNeeded(ctx android.BaseModuleContext) bool { return false }
+func (v *CcApiVariant) ImageMutatorBegin(ctx android.BaseModuleContext) {}
+func (v *CcApiVariant) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
+ return String(v.properties.Variant) == "ndk"
+}
func (v *CcApiVariant) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { return false }
func (v *CcApiVariant) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { return false }
func (v *CcApiVariant) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { return false }
@@ -359,7 +434,7 @@
var variations []string
platformVndkVersion := ctx.DeviceConfig().PlatformVndkVersion()
- if proptools.String(v.properties.Variant) == "llndk" {
+ if String(v.properties.Variant) == "llndk" {
variations = append(variations, VendorVariationPrefix+platformVndkVersion)
variations = append(variations, ProductVariationPrefix+platformVndkVersion)
}
diff --git a/cc/library_stub_test.go b/cc/library_stub_test.go
index 8ce74c4..e372860 100644
--- a/cc/library_stub_test.go
+++ b/cc/library_stub_test.go
@@ -322,16 +322,188 @@
ctx := prepareForCcTest.RunTestWithBp(t, bp)
- libfoo := ctx.ModuleForTests("binfoo", "android_vendor.29_arm64_armv8-a").Module()
+ binfoo := ctx.ModuleForTests("binfoo", "android_vendor.29_arm64_armv8-a").Module()
libbarApiImport := ctx.ModuleForTests("libbar.apiimport", "android_vendor.29_arm64_armv8-a_shared").Module()
libbarApiVariant := ctx.ModuleForTests("libbar.llndk.apiimport", "android_vendor.29_arm64_armv8-a").Module()
- android.AssertBoolEquals(t, "Stub library from API surface should be linked", true, hasDirectDependency(t, ctx, libfoo, libbarApiImport))
+ android.AssertBoolEquals(t, "Stub library from API surface should be linked", true, hasDirectDependency(t, ctx, binfoo, libbarApiImport))
android.AssertBoolEquals(t, "Stub library variant from API surface should be linked", true, hasDirectDependency(t, ctx, libbarApiImport, libbarApiVariant))
- libFooLibFlags := ctx.ModuleForTests("binfoo", "android_vendor.29_arm64_armv8-a").Rule("ld").Args["libFlags"]
- android.AssertStringDoesContain(t, "Vendor binary should be linked with LLNDK variant source", libFooLibFlags, "libbar_llndk.so")
+ binFooLibFlags := ctx.ModuleForTests("binfoo", "android_vendor.29_arm64_armv8-a").Rule("ld").Args["libFlags"]
+ android.AssertStringDoesContain(t, "Vendor binary should be linked with LLNDK variant source", binFooLibFlags, "libbar_llndk.so")
- libFooCFlags := ctx.ModuleForTests("binfoo", "android_vendor.29_arm64_armv8-a").Rule("cc").Args["cFlags"]
- android.AssertStringDoesContain(t, "Vendor binary should include headers from the LLNDK variant source", libFooCFlags, "-Ilibbar_llndk_include")
+ binFooCFlags := ctx.ModuleForTests("binfoo", "android_vendor.29_arm64_armv8-a").Rule("cc").Args["cFlags"]
+ android.AssertStringDoesContain(t, "Vendor binary should include headers from the LLNDK variant source", binFooCFlags, "-Ilibbar_llndk_include")
+}
+
+func TestApiLibraryWithNdkVariant(t *testing.T) {
+ bp := `
+ cc_binary {
+ name: "binfoo",
+ sdk_version: "29",
+ srcs: ["binfoo.cc"],
+ shared_libs: ["libbar"],
+ stl: "c++_shared",
+ }
+
+ cc_binary {
+ name: "binbaz",
+ sdk_version: "30",
+ srcs: ["binbaz.cc"],
+ shared_libs: ["libbar"],
+ stl: "c++_shared",
+ }
+
+ cc_api_library {
+ name: "libbar",
+ // TODO(b/244244438) Remove src property once all variants are implemented.
+ src: "libbar.so",
+ variants: [
+ "ndk.29",
+ "ndk.30",
+ "ndk.current",
+ ],
+ }
+
+ cc_api_variant {
+ name: "libbar",
+ variant: "ndk",
+ version: "29",
+ src: "libbar_ndk_29.so",
+ export_headers: ["libbar_ndk_29_include"]
+ }
+
+ cc_api_variant {
+ name: "libbar",
+ variant: "ndk",
+ version: "30",
+ src: "libbar_ndk_30.so",
+ export_headers: ["libbar_ndk_30_include"]
+ }
+
+ cc_api_variant {
+ name: "libbar",
+ variant: "ndk",
+ version: "current",
+ src: "libbar_ndk_current.so",
+ export_headers: ["libbar_ndk_current_include"]
+ }
+
+ api_imports {
+ name: "api_imports",
+ shared_libs: [
+ "libbar",
+ ],
+ header_libs: [],
+ }
+ `
+
+ ctx := prepareForCcTest.RunTestWithBp(t, bp)
+
+ binfoo := ctx.ModuleForTests("binfoo", "android_arm64_armv8-a_sdk").Module()
+ libbarApiImportv29 := ctx.ModuleForTests("libbar.apiimport", "android_arm64_armv8-a_sdk_shared_29").Module()
+ libbarApiVariantv29 := ctx.ModuleForTests("libbar.ndk.29.apiimport", "android_arm64_armv8-a_sdk").Module()
+ libbarApiImportv30 := ctx.ModuleForTests("libbar.apiimport", "android_arm64_armv8-a_sdk_shared_30").Module()
+ libbarApiVariantv30 := ctx.ModuleForTests("libbar.ndk.30.apiimport", "android_arm64_armv8-a_sdk").Module()
+
+ android.AssertBoolEquals(t, "Stub library from API surface should be linked with target version", true, hasDirectDependency(t, ctx, binfoo, libbarApiImportv29))
+ android.AssertBoolEquals(t, "Stub library variant from API surface should be linked with target version", true, hasDirectDependency(t, ctx, libbarApiImportv29, libbarApiVariantv29))
+ android.AssertBoolEquals(t, "Stub library from API surface should not be linked with different version", false, hasDirectDependency(t, ctx, binfoo, libbarApiImportv30))
+ android.AssertBoolEquals(t, "Stub library variant from API surface should not be linked with different version", false, hasDirectDependency(t, ctx, libbarApiImportv29, libbarApiVariantv30))
+
+ binbaz := ctx.ModuleForTests("binbaz", "android_arm64_armv8-a_sdk").Module()
+
+ android.AssertBoolEquals(t, "Stub library from API surface should be linked with target version", true, hasDirectDependency(t, ctx, binbaz, libbarApiImportv30))
+ android.AssertBoolEquals(t, "Stub library from API surface should not be linked with different version", false, hasDirectDependency(t, ctx, binbaz, libbarApiImportv29))
+
+ binFooLibFlags := ctx.ModuleForTests("binfoo", "android_arm64_armv8-a_sdk").Rule("ld").Args["libFlags"]
+ android.AssertStringDoesContain(t, "Binary using sdk should be linked with NDK variant source", binFooLibFlags, "libbar_ndk_29.so")
+
+ binFooCFlags := ctx.ModuleForTests("binfoo", "android_arm64_armv8-a_sdk").Rule("cc").Args["cFlags"]
+ android.AssertStringDoesContain(t, "Binary using sdk should include headers from the NDK variant source", binFooCFlags, "-Ilibbar_ndk_29_include")
+}
+
+func TestApiLibraryWithMultipleVariants(t *testing.T) {
+ bp := `
+ cc_binary {
+ name: "binfoo",
+ sdk_version: "29",
+ srcs: ["binfoo.cc"],
+ shared_libs: ["libbar"],
+ stl: "c++_shared",
+ }
+
+ cc_binary {
+ name: "binbaz",
+ vendor: true,
+ srcs: ["binbaz.cc"],
+ shared_libs: ["libbar"],
+ }
+
+ cc_api_library {
+ name: "libbar",
+ // TODO(b/244244438) Remove src property once all variants are implemented.
+ src: "libbar.so",
+ vendor_available: true,
+ variants: [
+ "llndk",
+ "ndk.29",
+ "ndk.30",
+ "ndk.current",
+ ],
+ }
+
+ cc_api_variant {
+ name: "libbar",
+ variant: "ndk",
+ version: "29",
+ src: "libbar_ndk_29.so",
+ export_headers: ["libbar_ndk_29_include"]
+ }
+
+ cc_api_variant {
+ name: "libbar",
+ variant: "ndk",
+ version: "30",
+ src: "libbar_ndk_30.so",
+ export_headers: ["libbar_ndk_30_include"]
+ }
+
+ cc_api_variant {
+ name: "libbar",
+ variant: "ndk",
+ version: "current",
+ src: "libbar_ndk_current.so",
+ export_headers: ["libbar_ndk_current_include"]
+ }
+
+ cc_api_variant {
+ name: "libbar",
+ variant: "llndk",
+ src: "libbar_llndk.so",
+ export_headers: ["libbar_llndk_include"]
+ }
+
+ api_imports {
+ name: "api_imports",
+ shared_libs: [
+ "libbar",
+ ],
+ header_libs: [],
+ }
+ `
+ ctx := prepareForCcTest.RunTestWithBp(t, bp)
+
+ binfoo := ctx.ModuleForTests("binfoo", "android_arm64_armv8-a_sdk").Module()
+ libbarApiImportv29 := ctx.ModuleForTests("libbar.apiimport", "android_arm64_armv8-a_sdk_shared_29").Module()
+ libbarApiImportLlndk := ctx.ModuleForTests("libbar.apiimport", "android_vendor.29_arm64_armv8-a_shared").Module()
+
+ android.AssertBoolEquals(t, "Binary using SDK should be linked with API library from NDK variant", true, hasDirectDependency(t, ctx, binfoo, libbarApiImportv29))
+ android.AssertBoolEquals(t, "Binary using SDK should not be linked with API library from LLNDK variant", false, hasDirectDependency(t, ctx, binfoo, libbarApiImportLlndk))
+
+ binbaz := ctx.ModuleForTests("binbaz", "android_vendor.29_arm64_armv8-a").Module()
+
+ android.AssertBoolEquals(t, "Vendor binary should be linked with API library from LLNDK variant", true, hasDirectDependency(t, ctx, binbaz, libbarApiImportLlndk))
+ android.AssertBoolEquals(t, "Vendor binary should not be linked with API library from NDK variant", false, hasDirectDependency(t, ctx, binbaz, libbarApiImportv29))
+
}
diff --git a/cc/sdk.go b/cc/sdk.go
index a0d196b..3e50c9f 100644
--- a/cc/sdk.go
+++ b/cc/sdk.go
@@ -31,6 +31,7 @@
switch m := ctx.Module().(type) {
case LinkableInterface:
+ ccModule, isCcModule := ctx.Module().(*Module)
if m.AlwaysSdk() {
if !m.UseSdk() && !m.SplitPerApiLevel() {
ctx.ModuleErrorf("UseSdk() must return true when AlwaysSdk is set, did the factory forget to set Sdk_version?")
@@ -58,11 +59,32 @@
modules[1].(*Module).Properties.PreventInstall = true
}
ctx.AliasVariation("")
+ } else if isCcModule && ccModule.isImportedApiLibrary() {
+ apiLibrary, _ := ccModule.linker.(*apiLibraryDecorator)
+ if apiLibrary.hasNDKStubs() && ccModule.canUseSdk() {
+ // Handle cc_api_library module with NDK stubs and variants only which can use SDK
+ modules := ctx.CreateVariations("", "sdk")
+ modules[1].(*Module).Properties.IsSdkVariant = true
+ if ctx.Config().UnbundledBuildApps() {
+ // For an unbundled apps build, hide the platform variant from Make.
+ modules[0].(*Module).Properties.HideFromMake = true
+ modules[0].(*Module).Properties.PreventInstall = true
+ } else {
+ // For a platform build, mark the SDK variant so that it gets a ".sdk" suffix when
+ // exposed to Make.
+ modules[1].(*Module).Properties.SdkAndPlatformVariantVisibleToMake = true
+ modules[1].(*Module).Properties.PreventInstall = true
+ }
+ } else {
+ ccModule.Properties.Sdk_version = nil
+ ctx.CreateVariations("")
+ ctx.AliasVariation("")
+ }
} else {
- if m, ok := ctx.Module().(*Module); ok {
+ if isCcModule {
// Clear the sdk_version property for modules that don't have an SDK variant so
// later code doesn't get confused by it.
- m.Properties.Sdk_version = nil
+ ccModule.Properties.Sdk_version = nil
}
ctx.CreateVariations("")
ctx.AliasVariation("")
@@ -79,6 +101,11 @@
case *snapshotModule:
ctx.CreateVariations("")
case *CcApiVariant:
- ctx.CreateVariations("")
+ ccApiVariant, _ := ctx.Module().(*CcApiVariant)
+ if String(ccApiVariant.properties.Variant) == "ndk" {
+ ctx.CreateVariations("sdk")
+ } else {
+ ctx.CreateVariations("")
+ }
}
}
diff --git a/licenses/Android.bp b/licenses/Android.bp
index 54981e1..eabc303 100644
--- a/licenses/Android.bp
+++ b/licenses/Android.bp
@@ -839,84 +839,84 @@
license_kind {
name: "SPDX-license-identifier-LGPL",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
}
license_kind {
name: "SPDX-license-identifier-LGPL-2.0",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPL-2.0.html",
}
license_kind {
name: "SPDX-license-identifier-LGPL-2.0+",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPL-2.0+.html",
}
license_kind {
name: "SPDX-license-identifier-LGPL-2.0-only",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPL-2.0-only.html",
}
license_kind {
name: "SPDX-license-identifier-LGPL-2.0-or-later",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPL-2.0-or-later.html",
}
license_kind {
name: "SPDX-license-identifier-LGPL-2.1",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPL-2.1.html",
}
license_kind {
name: "SPDX-license-identifier-LGPL-2.1+",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPL-2.1+.html",
}
license_kind {
name: "SPDX-license-identifier-LGPL-2.1-only",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPL-2.1-only.html",
}
license_kind {
name: "SPDX-license-identifier-LGPL-2.1-or-later",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPL-2.1-or-later.html",
}
license_kind {
name: "SPDX-license-identifier-LGPL-3.0",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPL-3.0.html",
}
license_kind {
name: "SPDX-license-identifier-LGPL-3.0+",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPL-3.0+.html",
}
license_kind {
name: "SPDX-license-identifier-LGPL-3.0-only",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPL-3.0-only.html",
}
license_kind {
name: "SPDX-license-identifier-LGPL-3.0-or-later",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPL-3.0-or-later.html",
}
license_kind {
name: "SPDX-license-identifier-LGPLLR",
- conditions: ["restricted_allows_dynamic_linking"],
+ conditions: ["restricted_if_statically_linked"],
url: "https://spdx.org/licenses/LGPLLR.html",
}