diff options
Diffstat (limited to 'cc/library.go')
-rw-r--r-- | cc/library.go | 420 |
1 files changed, 249 insertions, 171 deletions
diff --git a/cc/library.go b/cc/library.go index 05661828b..532b7e9aa 100644 --- a/cc/library.go +++ b/cc/library.go @@ -25,6 +25,7 @@ import ( "sync" "android/soong/android" + "android/soong/cc/config" "github.com/google/blueprint" "github.com/google/blueprint/depset" @@ -64,21 +65,7 @@ type LibraryProperties struct { Static_ndk_lib *bool // Generate stubs to make this library accessible to APEXes. - Stubs struct { - // Relative path to the symbol map. The symbol map provides the list of - // symbols that are exported for stubs variant of this library. - Symbol_file *string `android:"path,arch_variant"` - - // List versions to generate stubs libs for. The version name "current" is always - // implicitly added. - Versions []string - - // Whether to not require the implementation of the library to be installed if a - // client of the stubs is installed. Defaults to true; set to false if the - // implementation is made available by some other means, e.g. in a Microdroid - // virtual machine. - Implementation_installable *bool - } `android:"arch_variant"` + Stubs StubsProperties `android:"arch_variant"` // set the name of the output Stem *string `android:"arch_variant"` @@ -127,6 +114,22 @@ type LibraryProperties struct { Vendor_public_library vendorPublicLibraryProperties } +type StubsProperties struct { + // Relative path to the symbol map. The symbol map provides the list of + // symbols that are exported for stubs variant of this library. + Symbol_file *string `android:"path,arch_variant"` + + // List versions to generate stubs libs for. The version name "current" is always + // implicitly added. + Versions []string + + // Whether to not require the implementation of the library to be installed if a + // client of the stubs is installed. Defaults to true; set to false if the + // implementation is made available by some other means, e.g. in a Microdroid + // virtual machine. + Implementation_installable *bool +} + // StaticProperties is a properties stanza to affect only attributes of the "static" variants of a // library module. type StaticProperties struct { @@ -457,11 +460,15 @@ func (library *libraryDecorator) linkerProps() []interface{} { return props } -// linkerFlags takes a Flags struct and augments it to contain linker flags that are defined by this -// library, or that are implied by attributes of this library (such as whether this library is a -// shared library). -func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { - flags = library.baseLinker.linkerFlags(ctx, flags) +func CommonLibraryLinkerFlags(ctx android.ModuleContext, flags Flags, + toolchain config.Toolchain, libName string) Flags { + + mod, ok := ctx.Module().(LinkableInterface) + + if !ok { + ctx.ModuleErrorf("trying to add linker flags to a non-LinkableInterface module.") + return flags + } // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because // all code is position independent, and then those warnings get promoted to @@ -469,27 +476,18 @@ func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Fla if !ctx.Windows() { flags.Global.CFlags = append(flags.Global.CFlags, "-fPIC") } - - if library.static() { - flags.Local.CFlags = append(flags.Local.CFlags, library.StaticProperties.Static.Cflags.GetOrDefault(ctx, nil)...) - } else if library.shared() { - flags.Local.CFlags = append(flags.Local.CFlags, library.SharedProperties.Shared.Cflags.GetOrDefault(ctx, nil)...) - } - - if library.shared() { - libName := library.getLibName(ctx) + if mod.Shared() { var f []string - if ctx.toolchain().Bionic() { + if toolchain.Bionic() { f = append(f, "-nostdlib", "-Wl,--gc-sections", ) } - if ctx.Darwin() { f = append(f, "-dynamiclib", - "-install_name @rpath/"+libName+flags.Toolchain.ShlibSuffix(), + "-install_name @rpath/"+libName+toolchain.ShlibSuffix(), ) if ctx.Arch().ArchType == android.X86 { f = append(f, @@ -499,16 +497,30 @@ func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Fla } else { f = append(f, "-shared") if !ctx.Windows() { - f = append(f, "-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix()) + f = append(f, "-Wl,-soname,"+libName+toolchain.ShlibSuffix()) } } - flags.Global.LdFlags = append(flags.Global.LdFlags, f...) } return flags } +// linkerFlags takes a Flags struct and augments it to contain linker flags that are defined by this +// library, or that are implied by attributes of this library (such as whether this library is a +// shared library). +func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { + flags = library.baseLinker.linkerFlags(ctx, flags) + flags = CommonLibraryLinkerFlags(ctx, flags, ctx.toolchain(), library.getLibName(ctx)) + if library.static() { + flags.Local.CFlags = append(flags.Local.CFlags, library.StaticProperties.Static.Cflags.GetOrDefault(ctx, nil)...) + } else if library.shared() { + flags.Local.CFlags = append(flags.Local.CFlags, library.SharedProperties.Shared.Cflags.GetOrDefault(ctx, nil)...) + } + + return flags +} + // compilerFlags takes a Flags and augments it to contain compile flags from global values, // per-target values, module type values, per-module Blueprints properties, extra flags from // `flags`, and generated sources from `deps`. @@ -527,7 +539,7 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags, d // Wipe all the module-local properties, leaving only the global properties. flags.Local = LocalOrGlobalFlags{} } - if library.buildStubs() { + if library.BuildStubs() { // Remove -include <file> when compiling stubs. Otherwise, the force included // headers might cause conflicting types error with the symbols in the // generated stubs source code. e.g. @@ -546,7 +558,7 @@ func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags, d flags.Local.CommonFlags = removeInclude(flags.Local.CommonFlags) flags.Local.CFlags = removeInclude(flags.Local.CFlags) - flags = addStubLibraryCompilerFlags(flags) + flags = AddStubLibraryCompilerFlags(flags) } return flags } @@ -567,6 +579,8 @@ func (library *libraryDecorator) getHeaderAbiCheckerProperties(m *Module) header } func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { + sharedFlags := ctx.getSharedFlags() + if ctx.IsLlndk() { // Get the matching SDK version for the vendor API level. version, err := android.GetSdkVersionForVendorApiLevel(ctx.Config().VendorApiLevel()) @@ -575,27 +589,27 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa } // This is the vendor variant of an LLNDK library, build the LLNDK stubs. - nativeAbiResult := parseNativeAbiDefinition(ctx, + nativeAbiResult := ParseNativeAbiDefinition(ctx, String(library.Properties.Llndk.Symbol_file), nativeClampedApiLevel(ctx, version), "--llndk") - objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc) + objs := CompileStubLibrary(ctx, flags, nativeAbiResult.StubSrc, sharedFlags) if !Bool(library.Properties.Llndk.Unversioned) { library.versionScriptPath = android.OptionalPathForPath( - nativeAbiResult.versionScript) + nativeAbiResult.VersionScript) } return objs } if ctx.IsVendorPublicLibrary() { - nativeAbiResult := parseNativeAbiDefinition(ctx, + nativeAbiResult := ParseNativeAbiDefinition(ctx, String(library.Properties.Vendor_public_library.Symbol_file), android.FutureApiLevel, "") - objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc) + objs := CompileStubLibrary(ctx, flags, nativeAbiResult.StubSrc, sharedFlags) if !Bool(library.Properties.Vendor_public_library.Unversioned) { - library.versionScriptPath = android.OptionalPathForPath(nativeAbiResult.versionScript) + library.versionScriptPath = android.OptionalPathForPath(nativeAbiResult.VersionScript) } return objs } - if library.buildStubs() { + if library.BuildStubs() { return library.compileModuleLibApiStubs(ctx, flags, deps) } @@ -616,10 +630,17 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa } if library.sabi.shouldCreateSourceAbiDump() { dirs := library.exportedIncludeDirsForAbiCheck(ctx) - flags.SAbiFlags = make([]string, 0, len(dirs)) + flags.SAbiFlags = make([]string, 0, len(dirs)+1) for _, dir := range dirs { flags.SAbiFlags = append(flags.SAbiFlags, "-I"+dir) } + // If this library does not export any include directory, do not append the flags + // so that the ABI tool dumps everything without filtering by the include directories. + // requiresGlobalIncludes returns whether this library can include CommonGlobalIncludes. + // If the library cannot include them, it cannot export them. + if len(dirs) > 0 && requiresGlobalIncludes(ctx) { + flags.SAbiFlags = append(flags.SAbiFlags, "${config.CommonGlobalIncludes}") + } totalLength := len(srcs) + len(deps.GeneratedSources) + len(sharedSrcs) + len(staticSrcs) if totalLength > 0 { @@ -635,27 +656,29 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary, srcs, android.PathsForModuleSrc(ctx, library.StaticProperties.Static.Tidy_disabled_srcs), android.PathsForModuleSrc(ctx, library.StaticProperties.Static.Tidy_timeout_srcs), - library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps)) + library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps, sharedFlags)) } else if library.shared() { srcs := android.PathsForModuleSrc(ctx, sharedSrcs) objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary, srcs, android.PathsForModuleSrc(ctx, library.SharedProperties.Shared.Tidy_disabled_srcs), android.PathsForModuleSrc(ctx, library.SharedProperties.Shared.Tidy_timeout_srcs), - library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps)) + library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps, sharedFlags)) } 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) +type ApiStubsParams struct { + NotInPlatform bool + IsNdk bool + BaseModuleName string + ModuleName string +} + +// GetApiStubsFlags calculates the genstubFlags string to pass to ParseNativeAbiDefinition +func GetApiStubsFlags(api ApiStubsParams) string { + var flag string + // 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. @@ -663,23 +686,24 @@ func (library *libraryDecorator) compileModuleLibApiStubs(ctx ModuleContext, fla // 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.notInPlatform() { + if api.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()) && + if !api.IsNdk && // 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") { + !strings.Contains(api.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()) { + if isBionic(api.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 @@ -687,23 +711,45 @@ func (library *libraryDecorator) compileModuleLibApiStubs(ctx ModuleContext, fla // 2. NotInPlatform will return true (since the source com.android.runtime does not exist) flag = "--apex" } - nativeAbiResult := parseNativeAbiDefinition(ctx, symbolFile, + + return flag +} + +// 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) + + apiParams := ApiStubsParams{ + NotInPlatform: ctx.notInPlatform(), + IsNdk: ctx.Module().(*Module).IsNdk(ctx.Config()), + BaseModuleName: ctx.baseModuleName(), + ModuleName: ctx.ModuleName(), + } + flag := GetApiStubsFlags(apiParams) + + nativeAbiResult := ParseNativeAbiDefinition(ctx, symbolFile, android.ApiLevelOrPanic(ctx, library.MutatedProperties.StubsVersion), flag) - objs := compileStubLibrary(ctx, flags, nativeAbiResult.stubSrc) + objs := CompileStubLibrary(ctx, flags, nativeAbiResult.StubSrc, ctx.getSharedFlags()) library.versionScriptPath = android.OptionalPathForPath( - nativeAbiResult.versionScript) - + 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) + if library.StubsVersion() == "current" && ctx.PrimaryArch() && !ctx.inRecovery() && !ctx.inProduct() && !ctx.inVendor() { + library.apiListCoverageXmlPath = ParseSymbolFileForAPICoverage(ctx, symbolFile) } return objs } type libraryInterface interface { - versionedInterface + VersionedInterface static() bool shared() bool @@ -727,32 +773,49 @@ type libraryInterface interface { apexAvailable() []string - getAPIListCoverageXMLPath() android.ModuleOutPath + setAPIListCoverageXMLPath(out android.ModuleOutPath) + symbolsFile() *string + setSymbolFilePath(path android.Path) + setVersionScriptPath(path android.OptionalPath) installable() *bool } -type versionedInterface interface { - buildStubs() bool - setBuildStubs(isLatest bool) - hasStubsVariants() bool - isStubsImplementationRequired() bool - setStubsVersion(string) - stubsVersion() string +func (library *libraryDecorator) symbolsFile() *string { + return library.Properties.Stubs.Symbol_file +} + +func (library *libraryDecorator) setSymbolFilePath(path android.Path) { + library.stubsSymbolFilePath = path +} + +func (library *libraryDecorator) setVersionScriptPath(path android.OptionalPath) { + library.versionScriptPath = path +} + +type VersionedInterface interface { + BuildStubs() bool + SetBuildStubs(isLatest bool) + HasStubsVariants() bool + IsStubsImplementationRequired() bool + SetStubsVersion(string) + StubsVersion() string + + StubsVersions(ctx android.BaseModuleContext) []string + SetAllStubsVersions([]string) + AllStubsVersions() []string - stubsVersions(ctx android.BaseModuleContext) []string - setAllStubsVersions([]string) - allStubsVersions() []string + ImplementationModuleName(name string) string + HasLLNDKStubs() bool + HasLLNDKHeaders() bool + HasVendorPublicLibrary() bool + IsLLNDKMovedToApex() bool - implementationModuleName(name string) string - hasLLNDKStubs() bool - hasLLNDKHeaders() bool - hasVendorPublicLibrary() bool - isLLNDKMovedToApex() bool + GetAPIListCoverageXMLPath() android.ModuleOutPath } var _ libraryInterface = (*libraryDecorator)(nil) -var _ versionedInterface = (*libraryDecorator)(nil) +var _ VersionedInterface = (*libraryDecorator)(nil) func (library *libraryDecorator) getLibNameHelper(baseModuleName string, inVendor bool, inProduct bool) string { name := library.libName @@ -801,9 +864,9 @@ func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) { library.baseLinker.linkerInit(ctx) // Let baseLinker know whether this variant is for stubs or not, so that // it can omit things that are not required for linking stubs. - library.baseLinker.dynamicProperties.BuildStubs = library.buildStubs() + library.baseLinker.dynamicProperties.BuildStubs = library.BuildStubs() - if library.buildStubs() { + if library.BuildStubs() { macroNames := versioningMacroNamesList(ctx.Config()) myName := versioningMacroName(ctx.ModuleName()) versioningMacroNamesListMutex.Lock() @@ -962,8 +1025,8 @@ func (library *libraryDecorator) moduleInfoJSON(ctx ModuleContext, moduleInfoJSO moduleInfoJSON.Uninstallable = true } - if library.buildStubs() && library.stubsVersion() != "" { - moduleInfoJSON.SubName += "." + library.stubsVersion() + if library.BuildStubs() && library.StubsVersion() != "" { + moduleInfoJSON.SubName += "." + library.StubsVersion() } // If a library providing a stub is included in an APEX, the private APIs of the library @@ -974,10 +1037,10 @@ func (library *libraryDecorator) moduleInfoJSON(ctx ModuleContext, moduleInfoJSO // very early stage in the boot process). if len(library.Properties.Stubs.Versions) > 0 && !ctx.Host() && ctx.notInPlatform() && !ctx.inRamdisk() && !ctx.inVendorRamdisk() && !ctx.inRecovery() && !ctx.useVndk() && !ctx.static() { - if library.buildStubs() && library.isLatestStubVersion() { + if library.BuildStubs() && library.isLatestStubVersion() { moduleInfoJSON.SubName = "" } - if !library.buildStubs() { + if !library.BuildStubs() { moduleInfoJSON.SubName = ".bootstrap" } } @@ -1120,7 +1183,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, stripFlags := flagsToStripFlags(flags) needsStrip := library.stripper.NeedsStrip(ctx) - if library.buildStubs() { + if library.BuildStubs() { // No need to strip stubs libraries needsStrip = false } @@ -1174,7 +1237,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, linkerDeps = append(linkerDeps, deps.SharedLibsDeps...) linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...) - if generatedLib := generateRustStaticlib(ctx, deps.RustRlibDeps); generatedLib != nil && !library.buildStubs() { + if generatedLib := GenerateRustStaticlib(ctx, deps.RustRlibDeps); generatedLib != nil && !library.BuildStubs() { if ctx.Module().(*Module).WholeRustStaticlib { deps.WholeStaticLibs = append(deps.WholeStaticLibs, generatedLib) } else { @@ -1205,18 +1268,18 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, SharedLibrary: unstrippedOutputFile, TransitiveStaticLibrariesForOrdering: transitiveStaticLibrariesForOrdering, Target: ctx.Target(), - IsStubs: library.buildStubs(), + IsStubs: library.BuildStubs(), }) - addStubDependencyProviders(ctx) + AddStubDependencyProviders(ctx) return unstrippedOutputFile } // Visits the stub variants of the library and returns a struct containing the stub .so paths -func addStubDependencyProviders(ctx ModuleContext) []SharedStubLibrary { +func AddStubDependencyProviders(ctx android.BaseModuleContext) []SharedStubLibrary { stubsInfo := []SharedStubLibrary{} - stubs := ctx.GetDirectDepsProxyWithTag(stubImplDepTag) + stubs := ctx.GetDirectDepsProxyWithTag(StubImplDepTag) if len(stubs) > 0 { for _, stub := range stubs { stubInfo, ok := android.OtherModuleProvider(ctx, stub, SharedLibraryInfoProvider) @@ -1237,10 +1300,11 @@ func addStubDependencyProviders(ctx ModuleContext) []SharedStubLibrary { if len(stubsInfo) > 0 { android.SetProvider(ctx, SharedLibraryStubsProvider, SharedLibraryStubsInfo{ SharedStubLibraries: stubsInfo, - IsLLNDK: ctx.IsLlndk(), + IsLLNDK: ctx.Module().(LinkableInterface).IsLlndk(), }) } } + return stubsInfo } @@ -1257,7 +1321,7 @@ func (library *libraryDecorator) disableStripping() { } func (library *libraryDecorator) nativeCoverage() bool { - if library.header() || library.buildStubs() { + if library.header() || library.BuildStubs() { return false } return true @@ -1305,13 +1369,15 @@ func (library *libraryDecorator) linkLlndkSAbiDumpFiles(ctx ModuleContext, deps PathDeps, sAbiDumpFiles android.Paths, soFile android.Path, libFileName string, excludeSymbolVersions, excludeSymbolTags []string, sdkVersionForVendorApiLevel string) android.Path { + // Though LLNDK is implemented in system, the callers in vendor cannot include CommonGlobalIncludes, + // so commonGlobalIncludes is false. return transformDumpToLinkedDump(ctx, sAbiDumpFiles, soFile, libFileName+".llndk", library.llndkIncludeDirsForAbiCheck(ctx, deps), android.OptionalPathForModuleSrc(ctx, library.Properties.Llndk.Symbol_file), append([]string{"*_PLATFORM", "*_PRIVATE"}, excludeSymbolVersions...), append([]string{"platform-only"}, excludeSymbolTags...), - []string{"llndk"}, sdkVersionForVendorApiLevel) + []string{"llndk"}, sdkVersionForVendorApiLevel, false /* commonGlobalIncludes */) } func (library *libraryDecorator) linkApexSAbiDumpFiles(ctx ModuleContext, @@ -1324,7 +1390,7 @@ func (library *libraryDecorator) linkApexSAbiDumpFiles(ctx ModuleContext, android.OptionalPathForModuleSrc(ctx, library.Properties.Stubs.Symbol_file), append([]string{"*_PLATFORM", "*_PRIVATE"}, excludeSymbolVersions...), append([]string{"platform-only"}, excludeSymbolTags...), - []string{"apex", "systemapi"}, sdkVersion) + []string{"apex", "systemapi"}, sdkVersion, requiresGlobalIncludes(ctx)) } func getRefAbiDumpFile(ctx android.ModuleInstallPathContext, @@ -1467,7 +1533,7 @@ func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, deps PathD android.OptionalPathForModuleSrc(ctx, library.symbolFileForAbiCheck(ctx)), headerAbiChecker.Exclude_symbol_versions, headerAbiChecker.Exclude_symbol_tags, - []string{} /* includeSymbolTags */, currSdkVersion) + []string{} /* includeSymbolTags */, currSdkVersion, requiresGlobalIncludes(ctx)) var llndkDump, apexVariantDump android.Path tags := classifySourceAbiDump(ctx.Module().(*Module)) @@ -1726,9 +1792,9 @@ func (library *libraryDecorator) link(ctx ModuleContext, } func (library *libraryDecorator) exportVersioningMacroIfNeeded(ctx android.BaseModuleContext) { - if library.buildStubs() && library.stubsVersion() != "" && !library.skipAPIDefine { + if library.BuildStubs() && library.StubsVersion() != "" && !library.skipAPIDefine { name := versioningMacroName(ctx.Module().(*Module).ImplementationModuleName(ctx)) - apiLevel, err := android.ApiLevelFromUser(ctx, library.stubsVersion()) + apiLevel, err := android.ApiLevelFromUser(ctx, library.StubsVersion()) if err != nil { ctx.ModuleErrorf("Can't export version macro: %s", err.Error()) } @@ -1780,8 +1846,8 @@ func (library *libraryDecorator) installSymlinkToRuntimeApex(ctx ModuleContext, func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) { if library.shared() { translatedArch := ctx.Target().NativeBridge == android.NativeBridgeEnabled - if library.hasStubsVariants() && !ctx.Host() && !ctx.isSdkVariant() && - InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !library.buildStubs() && + if library.HasStubsVariants() && !ctx.Host() && !ctx.isSdkVariant() && + InstallToBootstrap(ctx.baseModuleName(), ctx.Config()) && !library.BuildStubs() && !translatedArch && !ctx.inRamdisk() && !ctx.inVendorRamdisk() && !ctx.inRecovery() { // Bionic libraries (e.g. libc.so) is installed to the bootstrap subdirectory. // The original path becomes a symlink to the corresponding file in the @@ -1798,7 +1864,7 @@ func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) { if Bool(library.Properties.Static_ndk_lib) && library.static() && !ctx.InVendorOrProduct() && !ctx.inRamdisk() && !ctx.inVendorRamdisk() && !ctx.inRecovery() && ctx.Device() && library.baseLinker.sanitize.isUnsanitizedVariant() && - ctx.isForPlatform() && !ctx.isPreventInstall() { + CtxIsForPlatform(ctx) && !ctx.isPreventInstall() { installPath := getUnversionedLibraryInstallPath(ctx).Join(ctx, file.Base()) ctx.ModuleBuild(pctx, android.ModuleBuildParams{ @@ -1868,32 +1934,32 @@ func (library *libraryDecorator) HeaderOnly() { 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 { +// 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.Symbol_file) != "" } // hasLLNDKStubs returns true if this cc_library module has a variant that will build LLNDK stubs. -func (library *libraryDecorator) hasLLNDKHeaders() bool { +func (library *libraryDecorator) HasLLNDKHeaders() bool { return Bool(library.Properties.Llndk.Llndk_headers) } -// isLLNDKMovedToApex returns true if this cc_library module sets the llndk.moved_to_apex property. -func (library *libraryDecorator) isLLNDKMovedToApex() bool { +// IsLLNDKMovedToApex returns true if this cc_library module sets the llndk.moved_to_apex property. +func (library *libraryDecorator) IsLLNDKMovedToApex() bool { return Bool(library.Properties.Llndk.Moved_to_apex) } -// hasVendorPublicLibrary returns true if this cc_library module has a variant that will build +// HasVendorPublicLibrary returns true if this cc_library module has a variant that will build // vendor public library stubs. -func (library *libraryDecorator) hasVendorPublicLibrary() bool { +func (library *libraryDecorator) HasVendorPublicLibrary() bool { return String(library.Properties.Vendor_public_library.Symbol_file) != "" } -func (library *libraryDecorator) implementationModuleName(name string) string { +func (library *libraryDecorator) ImplementationModuleName(name string) string { return name } -func (library *libraryDecorator) buildStubs() bool { +func (library *libraryDecorator) BuildStubs() bool { return library.MutatedProperties.BuildStubs } @@ -1901,7 +1967,7 @@ func (library *libraryDecorator) symbolFileForAbiCheck(ctx ModuleContext) *strin if props := library.getHeaderAbiCheckerProperties(ctx.Module().(*Module)); props.Symbol_file != nil { return props.Symbol_file } - if library.hasStubsVariants() && library.Properties.Stubs.Symbol_file != nil { + if library.HasStubsVariants() && library.Properties.Stubs.Symbol_file != nil { return library.Properties.Stubs.Symbol_file } // TODO(b/309880485): Distinguish platform, NDK, LLNDK, and APEX version scripts. @@ -1911,35 +1977,35 @@ func (library *libraryDecorator) symbolFileForAbiCheck(ctx ModuleContext) *strin return nil } -func (library *libraryDecorator) hasStubsVariants() bool { +func (library *libraryDecorator) HasStubsVariants() bool { // Just having stubs.symbol_file is enough to create a stub variant. In that case // the stub for the future API level is created. return library.Properties.Stubs.Symbol_file != nil || len(library.Properties.Stubs.Versions) > 0 } -func (library *libraryDecorator) isStubsImplementationRequired() bool { +func (library *libraryDecorator) IsStubsImplementationRequired() bool { return BoolDefault(library.Properties.Stubs.Implementation_installable, true) } -func (library *libraryDecorator) stubsVersions(ctx android.BaseModuleContext) []string { - if !library.hasStubsVariants() { +func (library *libraryDecorator) StubsVersions(ctx android.BaseModuleContext) []string { + if !library.HasStubsVariants() { return nil } - if library.hasLLNDKStubs() && ctx.Module().(*Module).InVendorOrProduct() { + if library.HasLLNDKStubs() && ctx.Module().(*Module).InVendorOrProduct() { // LLNDK libraries only need a single stubs variant (""), which is // added automatically in createVersionVariations(). return nil } // Future API level is implicitly added if there isn't - versions := addCurrentVersionIfNotPresent(library.Properties.Stubs.Versions) - normalizeVersions(ctx, versions) + versions := AddCurrentVersionIfNotPresent(library.Properties.Stubs.Versions) + NormalizeVersions(ctx, versions) return versions } -func addCurrentVersionIfNotPresent(vers []string) []string { +func AddCurrentVersionIfNotPresent(vers []string) []string { if inList(android.FutureApiLevel.String(), vers) { return vers } @@ -1952,24 +2018,24 @@ func addCurrentVersionIfNotPresent(vers []string) []string { return append(vers, android.FutureApiLevel.String()) } -func (library *libraryDecorator) setStubsVersion(version string) { +func (library *libraryDecorator) SetStubsVersion(version string) { library.MutatedProperties.StubsVersion = version } -func (library *libraryDecorator) stubsVersion() string { +func (library *libraryDecorator) StubsVersion() string { return library.MutatedProperties.StubsVersion } -func (library *libraryDecorator) setBuildStubs(isLatest bool) { +func (library *libraryDecorator) SetBuildStubs(isLatest bool) { library.MutatedProperties.BuildStubs = true library.MutatedProperties.IsLatestVersion = isLatest } -func (library *libraryDecorator) setAllStubsVersions(versions []string) { +func (library *libraryDecorator) SetAllStubsVersions(versions []string) { library.MutatedProperties.AllStubsVersions = versions } -func (library *libraryDecorator) allStubsVersions() []string { +func (library *libraryDecorator) AllStubsVersions() []string { return library.MutatedProperties.AllStubsVersions } @@ -1998,7 +2064,7 @@ func (library *libraryDecorator) installable() *bool { } func (library *libraryDecorator) makeUninstallable(mod *Module) { - if library.static() && library.buildStatic() && !library.buildStubs() { + if library.static() && library.buildStatic() && !library.BuildStubs() { // If we're asked to make a static library uninstallable we don't do // anything since AndroidMkEntries always sets LOCAL_UNINSTALLABLE_MODULE // for these entries. This is done to still get the make targets for NOTICE @@ -2012,10 +2078,14 @@ func (library *libraryDecorator) getPartition() string { return library.path.Partition() } -func (library *libraryDecorator) getAPIListCoverageXMLPath() android.ModuleOutPath { +func (library *libraryDecorator) GetAPIListCoverageXMLPath() android.ModuleOutPath { return library.apiListCoverageXmlPath } +func (library *libraryDecorator) setAPIListCoverageXMLPath(xml android.ModuleOutPath) { + library.apiListCoverageXmlPath = xml +} + func (library *libraryDecorator) overriddenModules() []string { return library.Properties.Overrides } @@ -2159,6 +2229,9 @@ func (linkageTransitionMutator) Split(ctx android.BaseModuleContext) []string { } func (linkageTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string { + if ctx.DepTag() == android.PrebuiltDepTag { + return sourceVariation + } return "" } @@ -2215,11 +2288,13 @@ func (linkageTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, varia library.setStatic() if !library.buildStatic() { library.disablePrebuilt() + ctx.Module().(*Module).Prebuilt().SetUsePrebuilt(false) } } else if variation == "shared" { library.setShared() if !library.buildShared() { library.disablePrebuilt() + ctx.Module().(*Module).Prebuilt().SetUsePrebuilt(false) } } } else if library, ok := ctx.Module().(LinkableInterface); ok && library.CcLibraryInterface() { @@ -2242,10 +2317,10 @@ func (linkageTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, varia } } -// normalizeVersions modifies `versions` in place, so that each raw version +// NormalizeVersions modifies `versions` in place, so that each raw version // string becomes its normalized canonical form. // Validates that the versions in `versions` are specified in least to greatest order. -func normalizeVersions(ctx android.BaseModuleContext, versions []string) { +func NormalizeVersions(ctx android.BaseModuleContext, versions []string) { var previous android.ApiLevel for i, v := range versions { ver, err := android.ApiLevelFromUser(ctx, v) @@ -2262,7 +2337,7 @@ func normalizeVersions(ctx android.BaseModuleContext, versions []string) { } func perApiVersionVariations(mctx android.BaseModuleContext, minSdkVersion string) []string { - from, err := nativeApiLevelFromUser(mctx, minSdkVersion) + from, err := NativeApiLevelFromUser(mctx, minSdkVersion) if err != nil { mctx.PropertyErrorf("min_sdk_version", err.Error()) return []string{""} @@ -2290,25 +2365,25 @@ func canBeVersionVariant(module interface { module.CcLibraryInterface() && module.Shared() } -func moduleLibraryInterface(module blueprint.Module) libraryInterface { - if m, ok := module.(*Module); ok { - return m.library +func moduleVersionedInterface(module blueprint.Module) VersionedInterface { + if m, ok := module.(VersionedLinkableInterface); ok { + return m.VersionedInterface() } return nil } // setStubsVersions normalizes the versions in the Stubs.Versions property into MutatedProperties.AllStubsVersions. -func setStubsVersions(mctx android.BaseModuleContext, library libraryInterface, module *Module) { - if !library.buildShared() || !canBeVersionVariant(module) { +func setStubsVersions(mctx android.BaseModuleContext, module VersionedLinkableInterface) { + if !module.BuildSharedVariant() || !canBeVersionVariant(module) { return } - versions := library.stubsVersions(mctx) + versions := module.VersionedInterface().StubsVersions(mctx) if mctx.Failed() { return } // 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) + module.VersionedInterface().SetAllStubsVersions(versions) } // versionTransitionMutator splits a module into the mandatory non-stubs variant @@ -2319,20 +2394,22 @@ func (versionTransitionMutator) Split(ctx android.BaseModuleContext) []string { if ctx.Os() != android.Android { return []string{""} } - - m, ok := ctx.Module().(*Module) - if library := moduleLibraryInterface(ctx.Module()); library != nil && canBeVersionVariant(m) { - setStubsVersions(ctx, library, m) - - return append(slices.Clone(library.allStubsVersions()), "") - } else if ok && m.SplitPerApiLevel() && m.IsSdkVariant() { - return perApiVersionVariations(ctx, m.MinSdkVersion()) + if m, ok := ctx.Module().(VersionedLinkableInterface); ok { + if m.CcLibraryInterface() && canBeVersionVariant(m) { + setStubsVersions(ctx, m) + return append(slices.Clone(m.VersionedInterface().AllStubsVersions()), "") + } else if m.SplitPerApiLevel() && m.IsSdkVariant() { + return perApiVersionVariations(ctx, m.MinSdkVersion()) + } } return []string{""} } func (versionTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string { + if ctx.DepTag() == android.PrebuiltDepTag { + return sourceVariation + } return "" } @@ -2340,11 +2417,11 @@ func (versionTransitionMutator) IncomingTransition(ctx android.IncomingTransitio if ctx.Os() != android.Android { return "" } - m, ok := ctx.Module().(*Module) - if library := moduleLibraryInterface(ctx.Module()); library != nil && canBeVersionVariant(m) { + m, ok := ctx.Module().(VersionedLinkableInterface) + if library := moduleVersionedInterface(ctx.Module()); library != nil && canBeVersionVariant(m) { if incomingVariation == "latest" { latestVersion := "" - versions := library.allStubsVersions() + versions := library.AllStubsVersions() if len(versions) > 0 { latestVersion = versions[len(versions)-1] } @@ -2369,39 +2446,39 @@ func (versionTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, varia return } - m, ok := ctx.Module().(*Module) - if library := moduleLibraryInterface(ctx.Module()); library != nil && canBeVersionVariant(m) { + m, ok := ctx.Module().(VersionedLinkableInterface) + if library := moduleVersionedInterface(ctx.Module()); library != nil && canBeVersionVariant(m) { isLLNDK := m.IsLlndk() isVendorPublicLibrary := m.IsVendorPublicLibrary() if variation != "" || isLLNDK || isVendorPublicLibrary { // A stubs or LLNDK stubs variant. - if m.sanitize != nil { - m.sanitize.Properties.ForceDisable = true - } - if m.stl != nil { - m.stl.Properties.Stl = StringPtr("none") + if sm, ok := ctx.Module().(PlatformSanitizeable); ok && sm.SanitizePropDefined() { + sm.ForceDisableSanitizers() } - m.Properties.PreventInstall = true - lib := moduleLibraryInterface(m) - allStubsVersions := library.allStubsVersions() + m.SetStl("none") + m.SetPreventInstall() + allStubsVersions := m.VersionedInterface().AllStubsVersions() isLatest := len(allStubsVersions) > 0 && variation == allStubsVersions[len(allStubsVersions)-1] - lib.setBuildStubs(isLatest) + m.VersionedInterface().SetBuildStubs(isLatest) } if variation != "" { // A non-LLNDK stubs module is hidden from make - library.setStubsVersion(variation) - m.Properties.HideFromMake = true + m.VersionedInterface().SetStubsVersion(variation) + m.SetHideFromMake() } else { // A non-LLNDK implementation module has a dependency to all stubs versions - for _, version := range library.allStubsVersions() { - ctx.AddVariationDependencies([]blueprint.Variation{{"version", version}}, - stubImplDepTag, ctx.ModuleName()) + for _, version := range m.VersionedInterface().AllStubsVersions() { + ctx.AddVariationDependencies( + []blueprint.Variation{ + {Mutator: "version", Variation: version}, + {Mutator: "link", Variation: "shared"}}, + StubImplDepTag, ctx.ModuleName()) } } } else if ok && m.SplitPerApiLevel() && m.IsSdkVariant() { - m.Properties.Sdk_version = StringPtr(variation) - m.Properties.Min_sdk_version = StringPtr(variation) + m.SetSdkVersion(variation) + m.SetMinSdkVersion(variation) } } @@ -2415,7 +2492,8 @@ func maybeInjectBoringSSLHash(ctx android.ModuleContext, outputFile android.Modu injectBoringSSLHash := Bool(inject) ctx.VisitDirectDepsProxy(func(dep android.ModuleProxy) { if tag, ok := ctx.OtherModuleDependencyTag(dep).(libraryDependencyTag); ok && tag.static() { - if ccInfo, ok := android.OtherModuleProvider(ctx, dep, CcInfoProvider); ok && ccInfo.LinkerInfo.LibraryDecoratorInfo != nil { + if ccInfo, ok := android.OtherModuleProvider(ctx, dep, CcInfoProvider); ok && + ccInfo.LinkerInfo != nil && ccInfo.LinkerInfo.LibraryDecoratorInfo != nil { if ccInfo.LinkerInfo.LibraryDecoratorInfo.InjectBsslHash { injectBoringSSLHash = true } |