Incorporate cc_library_headers into mixed builds
Test: go soong tests Test: bp2build generate & sync; mixed build libc; mixed build su (su is an Android.mk target that relies on converted a cc_library_headers) Bug: 181552740 Change-Id: I9efd587970551fd41f642a208f0aa0a80e8694e0
This commit is contained in:
@@ -191,17 +191,31 @@ func makeOverrideModuleNames(ctx AndroidMkContext, overrides []string) []string
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) androidMkWriteExportedFlags(entries *android.AndroidMkEntries) {
|
||||
exportedFlags := library.flagExporter.flags
|
||||
for _, dir := range library.flagExporter.dirs {
|
||||
var exportedFlags []string
|
||||
var includeDirs android.Paths
|
||||
var systemIncludeDirs android.Paths
|
||||
var exportedDeps android.Paths
|
||||
|
||||
if library.flagExporterInfo != nil {
|
||||
exportedFlags = library.flagExporterInfo.Flags
|
||||
includeDirs = library.flagExporterInfo.IncludeDirs
|
||||
systemIncludeDirs = library.flagExporterInfo.SystemIncludeDirs
|
||||
exportedDeps = library.flagExporterInfo.Deps
|
||||
} else {
|
||||
exportedFlags = library.flagExporter.flags
|
||||
includeDirs = library.flagExporter.dirs
|
||||
systemIncludeDirs = library.flagExporter.systemDirs
|
||||
exportedDeps = library.flagExporter.deps
|
||||
}
|
||||
for _, dir := range includeDirs {
|
||||
exportedFlags = append(exportedFlags, "-I"+dir.String())
|
||||
}
|
||||
for _, dir := range library.flagExporter.systemDirs {
|
||||
for _, dir := range systemIncludeDirs {
|
||||
exportedFlags = append(exportedFlags, "-isystem "+dir.String())
|
||||
}
|
||||
if len(exportedFlags) > 0 {
|
||||
entries.AddStrings("LOCAL_EXPORT_CFLAGS", exportedFlags...)
|
||||
}
|
||||
exportedDeps := library.flagExporter.deps
|
||||
if len(exportedDeps) > 0 {
|
||||
entries.AddStrings("LOCAL_EXPORT_C_INCLUDE_DEPS", exportedDeps.Strings()...)
|
||||
}
|
||||
|
@@ -426,7 +426,8 @@ type libraryDecorator struct {
|
||||
tocFile android.OptionalPath
|
||||
|
||||
flagExporter
|
||||
stripper Stripper
|
||||
flagExporterInfo *FlagExporterInfo
|
||||
stripper Stripper
|
||||
|
||||
// For whole_static_libs
|
||||
objects Objects
|
||||
|
@@ -43,6 +43,52 @@ func RegisterLibraryHeadersBuildComponents(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("cc_prebuilt_library_headers", prebuiltLibraryHeaderFactory)
|
||||
}
|
||||
|
||||
type libraryHeaderBazelHander struct {
|
||||
bazelHandler
|
||||
|
||||
module *Module
|
||||
library *libraryDecorator
|
||||
}
|
||||
|
||||
func (h *libraryHeaderBazelHander) generateBazelBuildActions(ctx android.ModuleContext, label string) bool {
|
||||
bazelCtx := ctx.Config().BazelContext
|
||||
ccInfo, ok, err := bazelCtx.GetCcInfo(label, ctx.Arch().ArchType)
|
||||
if err != nil {
|
||||
ctx.ModuleErrorf("Error getting Bazel CcInfo: %s", err)
|
||||
return false
|
||||
}
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
outputPaths := ccInfo.OutputFiles
|
||||
if len(outputPaths) != 1 {
|
||||
ctx.ModuleErrorf("expected exactly one output file for %q, but got %q", label, outputPaths)
|
||||
return false
|
||||
}
|
||||
|
||||
outputPath := android.PathForBazelOut(ctx, outputPaths[0])
|
||||
h.module.outputFile = android.OptionalPathForPath(outputPath)
|
||||
|
||||
// HeaderLibraryInfo is an empty struct to indicate to dependencies that this is a header library
|
||||
ctx.SetProvider(HeaderLibraryInfoProvider, HeaderLibraryInfo{})
|
||||
|
||||
flagExporterInfo := flagExporterInfoFromCcInfo(ctx, ccInfo)
|
||||
// Store flag info to be passed along to androimk
|
||||
// TODO(b/184387147): Androidmk should be done in Bazel, not Soong.
|
||||
h.library.flagExporterInfo = &flagExporterInfo
|
||||
// flag exporters consolidates properties like includes, flags, dependencies that should be
|
||||
// exported from this module to other modules
|
||||
ctx.SetProvider(FlagExporterInfoProvider, flagExporterInfo)
|
||||
|
||||
// Dependencies on this library will expect collectedSnapshotHeaders to be set, otherwise
|
||||
// validation will fail. For now, set this to an empty list.
|
||||
// TODO(cparsons): More closely mirror the collectHeadersForSnapshot implementation.
|
||||
h.library.collectedSnapshotHeaders = android.Paths{}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// cc_library_headers contains a set of c/c++ headers which are imported by
|
||||
// other soong cc modules using the header_libs property. For best practices,
|
||||
// use export_include_dirs property or LOCAL_EXPORT_C_INCLUDE_DIRS for
|
||||
@@ -51,6 +97,7 @@ func LibraryHeaderFactory() android.Module {
|
||||
module, library := NewLibrary(android.HostAndDeviceSupported)
|
||||
library.HeaderOnly()
|
||||
module.sdkMemberTypes = []android.SdkMemberType{headersLibrarySdkMemberType}
|
||||
module.bazelHandler = &libraryHeaderBazelHander{module: module, library: library}
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
@@ -162,9 +162,16 @@ func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMembe
|
||||
return &nativeLibInfoProperties{memberType: mt}
|
||||
}
|
||||
|
||||
func isBazelOutDirectory(p android.Path) bool {
|
||||
_, bazel := p.(android.BazelOutPath)
|
||||
return bazel
|
||||
}
|
||||
|
||||
func isGeneratedHeaderDirectory(p android.Path) bool {
|
||||
_, gen := p.(android.WritablePath)
|
||||
return gen
|
||||
// TODO(b/183213331): Here we assume that bazel-based headers are not generated; we need
|
||||
// to support generated headers in mixed builds.
|
||||
return gen && !isBazelOutDirectory(p)
|
||||
}
|
||||
|
||||
type includeDirsProperty struct {
|
||||
|
@@ -2,6 +2,7 @@ package cc
|
||||
|
||||
import (
|
||||
"android/soong/android"
|
||||
"android/soong/bazel/cquery"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
)
|
||||
@@ -274,3 +275,15 @@ type FlagExporterInfo struct {
|
||||
}
|
||||
|
||||
var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
|
||||
|
||||
// flagExporterInfoFromCcInfo populates FlagExporterInfo provider with information from Bazel.
|
||||
func flagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) FlagExporterInfo {
|
||||
|
||||
includes := android.PathsForBazelOut(ctx, ccInfo.Includes)
|
||||
systemIncludes := android.PathsForBazelOut(ctx, ccInfo.SystemIncludes)
|
||||
|
||||
return FlagExporterInfo{
|
||||
IncludeDirs: includes,
|
||||
SystemIncludeDirs: systemIncludes,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user