Refactor and cleanup of cquery processing

Test: USE_BAZEL_ANALYSIS=1 m libc
Change-Id: Iaf9a92e84d39c132e2444a8aaafd79505a12b8ec
This commit is contained in:
Chris Parsons
2021-03-11 11:08:46 -05:00
parent 2bed9ffaf4
commit 944e7d01aa
6 changed files with 246 additions and 114 deletions

View File

@@ -415,38 +415,39 @@ type staticLibraryBazelHandler struct {
func (handler *staticLibraryBazelHandler) generateBazelBuildActions(ctx android.ModuleContext, label string) bool {
bazelCtx := ctx.Config().BazelContext
outputPaths, objPaths, ok := bazelCtx.GetAllFilesAndCcObjectFiles(label, ctx.Arch().ArchType)
if ok {
if len(outputPaths) != 1 {
// TODO(cparsons): This is actually expected behavior for static libraries with no srcs.
// We should support this.
ctx.ModuleErrorf("expected exactly one output file for '%s', but got %s", label, objPaths)
return false
}
outputFilePath := android.PathForBazelOut(ctx, outputPaths[0])
handler.module.outputFile = android.OptionalPathForPath(outputFilePath)
objFiles := make(android.Paths, len(objPaths))
for i, objPath := range objPaths {
objFiles[i] = android.PathForBazelOut(ctx, objPath)
}
objects := Objects{
objFiles: objFiles,
}
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
StaticLibrary: outputFilePath,
ReuseObjects: objects,
Objects: objects,
// TODO(cparsons): Include transitive static libraries in this provider to support
// static libraries with deps.
TransitiveStaticLibrariesForOrdering: android.NewDepSetBuilder(android.TOPOLOGICAL).
Direct(outputFilePath).
Build(),
})
handler.module.outputFile = android.OptionalPathForPath(android.PathForBazelOut(ctx, objPaths[0]))
outputPaths, objPaths, ok := bazelCtx.GetOutputFilesAndCcObjectFiles(label, ctx.Arch().ArchType)
if !ok {
return ok
}
if len(outputPaths) != 1 {
// TODO(cparsons): This is actually expected behavior for static libraries with no srcs.
// We should support this.
ctx.ModuleErrorf("expected exactly one output file for '%s', but got %s", label, objPaths)
return false
}
outputFilePath := android.PathForBazelOut(ctx, outputPaths[0])
handler.module.outputFile = android.OptionalPathForPath(outputFilePath)
objFiles := make(android.Paths, len(objPaths))
for i, objPath := range objPaths {
objFiles[i] = android.PathForBazelOut(ctx, objPath)
}
objects := Objects{
objFiles: objFiles,
}
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
StaticLibrary: outputFilePath,
ReuseObjects: objects,
Objects: objects,
// TODO(cparsons): Include transitive static libraries in this provider to support
// static libraries with deps.
TransitiveStaticLibrariesForOrdering: android.NewDepSetBuilder(android.TOPOLOGICAL).
Direct(outputFilePath).
Build(),
})
handler.module.outputFile = android.OptionalPathForPath(android.PathForBazelOut(ctx, objPaths[0]))
return ok
}