Don't rewrite LLNDK dependencies with .llndk suffix
Rewriting LLNDK dependencies with .llndk suffix requries referencing
a global data structure to determine if a given library is an LLNDK
library and therefore needs the .llndk suffix. References to
global data structures from mutators must be removed to support
incremental Soong analysis. Instead, move the LLNDK stubs rules
into the vendor variant of the implementing cc_library so that
the original name can be used.
As an incremental step, the llndk_library modules are left in
place, and the properties are copied into the cc_library via
the dependency specified by the llndk_stub property. A followup
will move the LLNDK properties directly into the cc_library and
delete the llndk_library modules.
The global list of LLNDK libraries is kept for now as it is used
to generate the vndk.libraries.txt file.
Bug: 170784825
Test: m checkbuild
Test: compare Soong outputs
Test: all Soong tests
Change-Id: I2a942b21c162541a49e27b2e5833c9aebccff1d0
diff --git a/cc/library.go b/cc/library.go
index d5c9131..1d0c018 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -22,6 +22,7 @@
"strings"
"sync"
+ "github.com/google/blueprint"
"github.com/google/blueprint/pathtools"
"android/soong/android"
@@ -114,6 +115,10 @@
// If this is an LLNDK library, the name of the equivalent llndk_library module.
Llndk_stubs *string
+
+ // If this is an LLNDK library, properties to describe the LLNDK stubs. Will be copied from
+ // the module pointed to by llndk_stubs if it is set.
+ Llndk llndkLibraryProperties
}
// StaticProperties is a properties stanza to affect only attributes of the "static" variants of a
@@ -570,6 +575,12 @@
}
flags = library.baseCompiler.compilerFlags(ctx, flags, deps)
+ if ctx.IsLlndk() {
+ // LLNDK libraries ignore most of the properties on the cc_library and use the
+ // LLNDK-specific properties instead.
+ // Wipe all the module-local properties, leaving only the global properties.
+ flags.Local = LocalOrGlobalFlags{}
+ }
if library.buildStubs() {
// Remove -include <file> when compiling stubs. Otherwise, the force included
// headers might cause conflicting types error with the symbols in the
@@ -603,6 +614,22 @@
}
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
+ if ctx.IsLlndk() {
+ // This is the vendor variant of an LLNDK library, build the LLNDK stubs.
+ vndkVer := ctx.Module().(*Module).VndkVersion()
+ if !inList(vndkVer, ctx.Config().PlatformVersionActiveCodenames()) || vndkVer == "" {
+ // For non-enforcing devices, vndkVer is empty. Use "current" in that case, too.
+ vndkVer = "current"
+ }
+ if library.stubsVersion() != "" {
+ vndkVer = library.stubsVersion()
+ }
+ objs, versionScript := compileStubLibrary(ctx, flags, String(library.Properties.Llndk.Symbol_file), vndkVer, "--llndk")
+ if !Bool(library.Properties.Llndk.Unversioned) {
+ library.versionScriptPath = android.OptionalPathForPath(versionScript)
+ }
+ return objs
+ }
if library.buildStubs() {
objs, versionScript := compileStubLibrary(ctx, flags, String(library.Properties.Stubs.Symbol_file), library.MutatedProperties.StubsVersion, "--apex")
library.versionScriptPath = android.OptionalPathForPath(versionScript)
@@ -693,6 +720,7 @@
allStubsVersions() []string
implementationModuleName(name string) string
+ hasLLNDKStubs() bool
}
var _ libraryInterface = (*libraryDecorator)(nil)
@@ -768,12 +796,27 @@
}
func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
+ if ctx.IsLlndk() {
+ // LLNDK libraries ignore most of the properties on the cc_library and use the
+ // LLNDK-specific properties instead.
+ return deps
+ }
+
deps = library.baseCompiler.compilerDeps(ctx, deps)
return deps
}
func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
+ if ctx.IsLlndk() {
+ // LLNDK libraries ignore most of the properties on the cc_library and use the
+ // LLNDK-specific properties instead.
+ deps.HeaderLibs = append(deps.HeaderLibs, library.Properties.Llndk.Export_llndk_headers...)
+ deps.ReexportHeaderLibHeaders = append(deps.ReexportHeaderLibHeaders,
+ library.Properties.Llndk.Export_llndk_headers...)
+ return deps
+ }
+
if library.static() {
// Compare with nil because an empty list needs to be propagated.
if library.StaticProperties.Static.System_shared_libs != nil {
@@ -1022,7 +1065,7 @@
linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...)
linkerDeps = append(linkerDeps, objs.tidyFiles...)
- if Bool(library.Properties.Sort_bss_symbols_by_size) {
+ if Bool(library.Properties.Sort_bss_symbols_by_size) && !library.buildStubs() {
unsortedOutputFile := android.PathForModuleOut(ctx, "unsorted", fileName)
transformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs,
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
@@ -1076,7 +1119,7 @@
ctx.SetProvider(SharedLibraryStubsProvider, SharedLibraryStubsInfo{
SharedStubLibraries: stubsInfo,
- IsLLNDK: ctx.isLlndk(ctx.Config()),
+ IsLLNDK: ctx.IsLlndk(),
})
}
@@ -1105,7 +1148,7 @@
func getRefAbiDumpFile(ctx ModuleContext, vndkVersion, fileName string) android.Path {
// The logic must be consistent with classifySourceAbiDump.
isNdk := ctx.isNdk(ctx.Config())
- isLlndkOrVndk := ctx.isLlndkPublic(ctx.Config()) || (ctx.useVndk() && ctx.isVndk())
+ isLlndkOrVndk := ctx.IsLlndkPublic() || (ctx.useVndk() && ctx.isVndk())
refAbiDumpTextFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isNdk, isLlndkOrVndk, false)
refAbiDumpGzipFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isNdk, isLlndkOrVndk, true)
@@ -1158,17 +1201,64 @@
library.sAbiDiff = sourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
refAbiDumpFile, fileName, exportedHeaderFlags,
Bool(library.Properties.Header_abi_checker.Check_all_apis),
- ctx.isLlndk(ctx.Config()), ctx.isNdk(ctx.Config()), ctx.IsVndkExt())
+ ctx.IsLlndk(), ctx.isNdk(ctx.Config()), ctx.IsVndkExt())
}
}
}
+func processLLNDKHeaders(ctx ModuleContext, srcHeaderDir string, outDir android.ModuleGenPath) android.Path {
+ srcDir := android.PathForModuleSrc(ctx, srcHeaderDir)
+ srcFiles := ctx.GlobFiles(filepath.Join(srcDir.String(), "**/*.h"), nil)
+
+ var installPaths []android.WritablePath
+ for _, header := range srcFiles {
+ headerDir := filepath.Dir(header.String())
+ relHeaderDir, err := filepath.Rel(srcDir.String(), headerDir)
+ if err != nil {
+ ctx.ModuleErrorf("filepath.Rel(%q, %q) failed: %s",
+ srcDir.String(), headerDir, err)
+ continue
+ }
+
+ installPaths = append(installPaths, outDir.Join(ctx, relHeaderDir, header.Base()))
+ }
+
+ return processHeadersWithVersioner(ctx, srcDir, outDir, srcFiles, installPaths)
+}
+
// link registers actions to link this library, and sets various fields
// on this library to reflect information that should be exported up the build
// tree (for example, exported flags and include paths).
func (library *libraryDecorator) link(ctx ModuleContext,
flags Flags, deps PathDeps, objs Objects) android.Path {
+ if ctx.IsLlndk() {
+ if len(library.Properties.Llndk.Export_preprocessed_headers) > 0 {
+ // This is the vendor variant of an LLNDK library with preprocessed headers.
+ genHeaderOutDir := android.PathForModuleGen(ctx, "include")
+
+ var timestampFiles android.Paths
+ for _, dir := range library.Properties.Llndk.Export_preprocessed_headers {
+ timestampFiles = append(timestampFiles, processLLNDKHeaders(ctx, dir, genHeaderOutDir))
+ }
+
+ if Bool(library.Properties.Llndk.Export_headers_as_system) {
+ library.reexportSystemDirs(genHeaderOutDir)
+ } else {
+ library.reexportDirs(genHeaderOutDir)
+ }
+
+ library.reexportDeps(timestampFiles...)
+ }
+
+ if Bool(library.Properties.Llndk.Export_headers_as_system) {
+ library.flagExporter.Properties.Export_system_include_dirs = append(
+ library.flagExporter.Properties.Export_system_include_dirs,
+ library.flagExporter.Properties.Export_include_dirs...)
+ library.flagExporter.Properties.Export_include_dirs = nil
+ }
+ }
+
// Linking this library consists of linking `deps.Objs` (.o files in dependencies
// of this library), together with `objs` (.o files created by compiling this
// library).
@@ -1251,7 +1341,7 @@
}
func (library *libraryDecorator) exportVersioningMacroIfNeeded(ctx android.BaseModuleContext) {
- if library.buildStubs() && !library.skipAPIDefine {
+ if library.buildStubs() && library.stubsVersion() != "" && !library.skipAPIDefine {
name := versioningMacroName(ctx.Module().(*Module).ImplementationModuleName(ctx))
ver := library.stubsVersion()
library.reexportFlags("-D" + name + "=" + ver)
@@ -1339,7 +1429,7 @@
}
library.baseInstaller.subDir = "bootstrap"
}
- } else if ctx.directlyInAnyApex() && ctx.isLlndk(ctx.Config()) && !isBionic(ctx.baseModuleName()) {
+ } else if ctx.directlyInAnyApex() && ctx.IsLlndk() && !isBionic(ctx.baseModuleName()) {
// Skip installing LLNDK (non-bionic) libraries moved to APEX.
ctx.Module().HideFromMake()
}
@@ -1416,6 +1506,11 @@
library.MutatedProperties.BuildStatic = false
}
+// hasLLNDKStubs returns true if this cc_library module has a variant that will build LLNDK stubs.
+func (library *libraryDecorator) hasLLNDKStubs() bool {
+ return String(library.Properties.Llndk_stubs) != ""
+}
+
func (library *libraryDecorator) implementationModuleName(name string) string {
return name
}
@@ -1428,6 +1523,9 @@
if library.Properties.Header_abi_checker.Symbol_file != nil {
return library.Properties.Header_abi_checker.Symbol_file
}
+ if ctx.Module().(*Module).IsLlndk() {
+ return library.Properties.Llndk.Symbol_file
+ }
if library.hasStubsVariants() && library.Properties.Stubs.Symbol_file != nil {
return library.Properties.Stubs.Symbol_file
}
@@ -1592,7 +1690,9 @@
library := mctx.Module().(*Module).linker.(prebuiltLibraryInterface)
// Differentiate between header only and building an actual static/shared library
- if library.buildStatic() || library.buildShared() {
+ buildStatic := library.buildStatic()
+ buildShared := library.buildShared()
+ if buildStatic || buildShared {
// Always create both the static and shared variants for prebuilt libraries, and then disable the one
// that is not being used. This allows them to share the name of a cc_library module, which requires that
// all the variants of the cc_library also exist on the prebuilt.
@@ -1603,16 +1703,16 @@
static.linker.(prebuiltLibraryInterface).setStatic()
shared.linker.(prebuiltLibraryInterface).setShared()
- if library.buildShared() {
+ if buildShared {
mctx.AliasVariation("shared")
- } else if library.buildStatic() {
+ } else if buildStatic {
mctx.AliasVariation("static")
}
- if !library.buildStatic() {
+ if !buildStatic {
static.linker.(prebuiltLibraryInterface).disablePrebuilt()
}
- if !library.buildShared() {
+ if !buildShared {
shared.linker.(prebuiltLibraryInterface).disablePrebuilt()
}
} else {
@@ -1627,7 +1727,18 @@
variations = append(variations, "")
}
- if library.BuildStaticVariant() && library.BuildSharedVariant() {
+ isLLNDK := false
+ if m, ok := mctx.Module().(*Module); ok {
+ isLLNDK = m.IsLlndk()
+ // Don't count the vestigial llndk_library module as isLLNDK, it needs a static
+ // variant so that a cc_library_prebuilt can depend on it.
+ if _, ok := m.linker.(*llndkStubDecorator); ok {
+ isLLNDK = false
+ }
+ }
+ buildStatic := library.BuildStaticVariant() && !isLLNDK
+ buildShared := library.BuildSharedVariant()
+ if buildStatic && buildShared {
variations := append([]string{"static", "shared"}, variations...)
modules := mctx.CreateLocalVariations(variations...)
@@ -1641,13 +1752,13 @@
reuseStaticLibrary(mctx, static.(*Module), shared.(*Module))
}
mctx.AliasVariation("shared")
- } else if library.BuildStaticVariant() {
+ } else if buildStatic {
variations := append([]string{"static"}, variations...)
modules := mctx.CreateLocalVariations(variations...)
modules[0].(LinkableInterface).SetStatic()
mctx.AliasVariation("static")
- } else if library.BuildSharedVariant() {
+ } else if buildShared {
variations := append([]string{"shared"}, variations...)
modules := mctx.CreateLocalVariations(variations...)
@@ -1680,22 +1791,32 @@
}
func createVersionVariations(mctx android.BottomUpMutatorContext, versions []string) {
- // "" is for the non-stubs (implementation) variant.
+ // "" is for the non-stubs (implementation) variant for system modules, or the LLNDK variant
+ // for LLNDK modules.
variants := append(android.CopyOf(versions), "")
+ m := mctx.Module().(*Module)
+ isLLNDK := m.IsLlndk()
+
modules := mctx.CreateLocalVariations(variants...)
for i, m := range modules {
- if variants[i] != "" {
+
+ if variants[i] != "" || isLLNDK {
+ // A stubs or LLNDK stubs variant.
c := m.(*Module)
- c.Properties.HideFromMake = true
c.sanitize = nil
c.stl = nil
c.Properties.PreventInstall = true
lib := moduleLibraryInterface(m)
lib.setBuildStubs()
- lib.setStubsVersion(variants[i])
- // The implementation depends on the stubs
- mctx.AddInterVariantDependency(stubImplDepTag, modules[len(modules)-1], modules[i])
+
+ if variants[i] != "" {
+ // A non-LLNDK stubs module is hidden from make and has a dependency from the
+ // implementation module to the stubs module.
+ c.Properties.HideFromMake = true
+ lib.setStubsVersion(variants[i])
+ mctx.AddInterVariantDependency(stubImplDepTag, modules[len(modules)-1], modules[i])
+ }
}
}
mctx.AliasVariation("")
@@ -1742,7 +1863,7 @@
module.CcLibraryInterface() && module.Shared()
}
-func moduleLibraryInterface(module android.Module) libraryInterface {
+func moduleLibraryInterface(module blueprint.Module) libraryInterface {
if m, ok := module.(*Module); ok {
return m.library
}
@@ -1763,7 +1884,15 @@
// Set the versions on the pre-mutated module so they can be read by any llndk modules that
// depend on the implementation library and haven't been mutated yet.
library.setAllStubsVersions(versions)
- return
+ }
+
+ if mctx.Module().(*Module).UseVndk() && library.hasLLNDKStubs() {
+ // Propagate the version to the llndk stubs module.
+ mctx.VisitDirectDepsWithTag(llndkStubDepTag, func(stubs android.Module) {
+ if stubsLib := moduleLibraryInterface(stubs); stubsLib != nil {
+ stubsLib.setAllStubsVersions(library.allStubsVersions())
+ }
+ })
}
}
}