Merge changes from topic "cc_prebuilt_stubs" into main

* changes:
  Skip `-Wl,--version-script` on libclang_rt.* stubs (temp hack)
  Special case the stubgen args for bionic libs
  Add stub generation support to cc_prebuilt_library
This commit is contained in:
Spandan Das
2024-08-27 19:37:08 +00:00
committed by Gerrit Code Review
4 changed files with 153 additions and 52 deletions

View File

@@ -594,43 +594,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
return objs
}
if library.buildStubs() {
symbolFile := String(library.Properties.Stubs.Symbol_file)
if symbolFile != "" && !strings.HasSuffix(symbolFile, ".map.txt") {
ctx.PropertyErrorf("symbol_file", "%q doesn't have .map.txt suffix", symbolFile)
return Objects{}
}
library.stubsSymbolFilePath = android.PathForModuleSrc(ctx, symbolFile)
// b/239274367 --apex and --systemapi filters symbols tagged with # apex and #
// systemapi, respectively. The former is for symbols defined in platform libraries
// and the latter is for symbols defined in APEXes.
// A single library can contain either # apex or # systemapi, but not both.
// The stub generator (ndkstubgen) is additive, so passing _both_ of these to it should be a no-op.
// However, having this distinction helps guard accidental
// promotion or demotion of API and also helps the API review process b/191371676
var flag string
if ctx.Module().(android.ApexModule).NotInPlatform() {
flag = "--apex"
} else {
flag = "--systemapi"
}
// b/184712170, unless the lib is an NDK library, exclude all public symbols from
// the stub so that it is mandated that all symbols are explicitly marked with
// either apex or systemapi.
if !ctx.Module().(*Module).IsNdk(ctx.Config()) {
flag = flag + " --no-ndk"
}
nativeAbiResult := parseNativeAbiDefinition(ctx, symbolFile,
android.ApiLevelOrPanic(ctx, library.MutatedProperties.StubsVersion), flag)
objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc)
library.versionScriptPath = android.OptionalPathForPath(
nativeAbiResult.versionScript)
// Parse symbol file to get API list for coverage
if library.stubsVersion() == "current" && ctx.PrimaryArch() && !ctx.inRecovery() && !ctx.inProduct() && !ctx.inVendor() {
library.apiListCoverageXmlPath = parseSymbolFileForAPICoverage(ctx, symbolFile)
}
return objs
return library.compileModuleLibApiStubs(ctx, flags, deps)
}
srcs := library.baseCompiler.Properties.Srcs.GetOrDefault(ctx, nil)
@@ -681,6 +645,61 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
return objs
}
// Compile stubs for the API surface between platform and apex
// This method will be used by source and prebuilt cc module types.
func (library *libraryDecorator) compileModuleLibApiStubs(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
// TODO (b/275273834): Make this a hard error when the symbol files have been added to module sdk.
if library.Properties.Stubs.Symbol_file == nil {
return Objects{}
}
symbolFile := String(library.Properties.Stubs.Symbol_file)
library.stubsSymbolFilePath = android.PathForModuleSrc(ctx, symbolFile)
// b/239274367 --apex and --systemapi filters symbols tagged with # apex and #
// systemapi, respectively. The former is for symbols defined in platform libraries
// and the latter is for symbols defined in APEXes.
// A single library can contain either # apex or # systemapi, but not both.
// The stub generator (ndkstubgen) is additive, so passing _both_ of these to it should be a no-op.
// However, having this distinction helps guard accidental
// promotion or demotion of API and also helps the API review process b/191371676
var flag string
if ctx.Module().(android.ApexModule).NotInPlatform() {
flag = "--apex"
} else {
flag = "--systemapi"
}
// b/184712170, unless the lib is an NDK library, exclude all public symbols from
// the stub so that it is mandated that all symbols are explicitly marked with
// either apex or systemapi.
if !ctx.Module().(*Module).IsNdk(ctx.Config()) &&
// the symbol files of libclang libs are autogenerated and do not contain systemapi tags
// TODO (spandandas): Update mapfile.py to include #systemapi tag on all symbols
!strings.Contains(ctx.ModuleName(), "libclang_rt") {
flag = flag + " --no-ndk"
}
// TODO(b/361303067): Remove this special case if bionic/ projects are added to ART development branches.
if isBionic(ctx.baseModuleName()) {
// set the flags explicitly for bionic libs.
// this is necessary for development in minimal branches which does not contain bionic/*.
// In such minimal branches, e.g. on the prebuilt libc stubs
// 1. IsNdk will return false (since the ndk_library definition for libc does not exist)
// 2. NotInPlatform will return true (since the source com.android.runtime does not exist)
flag = "--apex"
}
nativeAbiResult := parseNativeAbiDefinition(ctx, symbolFile,
android.ApiLevelOrPanic(ctx, library.MutatedProperties.StubsVersion), flag)
objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc)
library.versionScriptPath = android.OptionalPathForPath(
nativeAbiResult.versionScript)
// Parse symbol file to get API list for coverage
if library.stubsVersion() == "current" && ctx.PrimaryArch() && !ctx.inRecovery() && !ctx.inProduct() && !ctx.inVendor() {
library.apiListCoverageXmlPath = parseSymbolFileForAPICoverage(ctx, symbolFile)
}
return objs
}
type libraryInterface interface {
versionedInterface
@@ -1182,12 +1201,17 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
return unstrippedOutputFile
}
func addStubDependencyProviders(ctx ModuleContext) {
// Visits the stub variants of the library and returns a struct containing the stub .so paths
func addStubDependencyProviders(ctx ModuleContext) []SharedStubLibrary {
stubsInfo := []SharedStubLibrary{}
stubs := ctx.GetDirectDepsWithTag(stubImplDepTag)
if len(stubs) > 0 {
var stubsInfo []SharedStubLibrary
for _, stub := range stubs {
stubInfo, _ := android.OtherModuleProvider(ctx, stub, SharedLibraryInfoProvider)
stubInfo, ok := android.OtherModuleProvider(ctx, stub, SharedLibraryInfoProvider)
// TODO (b/275273834): Make this a hard error when the symbol files have been added to module sdk.
if !ok {
continue
}
flagInfo, _ := android.OtherModuleProvider(ctx, stub, FlagExporterInfoProvider)
stubsInfo = append(stubsInfo, SharedStubLibrary{
Version: moduleLibraryInterface(stub).stubsVersion(),
@@ -1195,11 +1219,14 @@ func addStubDependencyProviders(ctx ModuleContext) {
FlagExporterInfo: flagInfo,
})
}
android.SetProvider(ctx, SharedLibraryStubsProvider, SharedLibraryStubsInfo{
SharedStubLibraries: stubsInfo,
IsLLNDK: ctx.IsLlndk(),
})
if len(stubsInfo) > 0 {
android.SetProvider(ctx, SharedLibraryStubsProvider, SharedLibraryStubsInfo{
SharedStubLibraries: stubsInfo,
IsLLNDK: ctx.IsLlndk(),
})
}
}
return stubsInfo
}
func (library *libraryDecorator) unstrippedOutputFilePath() android.Path {