Consolidate cc-specific cqueries.
There is little overlap at this point, but we expect these to converge more over time, to handle exported includes, libs, etc., this will allow those changes to be handled in one place and allow more consolidation of code. Test: bp2build generate & sync; mixed build libc Change-Id: I51685dad9f4fc11a634965a3c9e84f4a0e279ecb
This commit is contained in:
@@ -5,14 +5,14 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
GetOutputFiles = &getOutputFilesRequestType{}
|
||||
GetOutputFilesAndCcObjectFiles = &getOutputFilesAndCcObjectFilesType{}
|
||||
GetPrebuiltCcStaticLibraryFiles = &getPrebuiltCcStaticLibraryFiles{}
|
||||
GetOutputFiles = &getOutputFilesRequestType{}
|
||||
GetCcInfo = &getCcInfoType{}
|
||||
)
|
||||
|
||||
type GetOutputFilesAndCcObjectFiles_Result struct {
|
||||
OutputFiles []string
|
||||
CcObjectFiles []string
|
||||
type CcInfo struct {
|
||||
OutputFiles []string
|
||||
CcObjectFiles []string
|
||||
CcStaticLibraryFiles []string
|
||||
}
|
||||
|
||||
type getOutputFilesRequestType struct{}
|
||||
@@ -42,12 +42,12 @@ func (g getOutputFilesRequestType) ParseResult(rawString string) []string {
|
||||
return strings.Split(rawString, ", ")
|
||||
}
|
||||
|
||||
type getOutputFilesAndCcObjectFilesType struct{}
|
||||
type getCcInfoType struct{}
|
||||
|
||||
// Name returns a string name for this request type. Such request type names must be unique,
|
||||
// and must only consist of alphanumeric characters.
|
||||
func (g getOutputFilesAndCcObjectFilesType) Name() string {
|
||||
return "getOutputFilesAndCcObjectFiles"
|
||||
func (g getCcInfoType) Name() string {
|
||||
return "getCcInfo"
|
||||
}
|
||||
|
||||
// StarlarkFunctionBody returns a starlark function body to process this request type.
|
||||
@@ -58,61 +58,49 @@ func (g getOutputFilesAndCcObjectFilesType) Name() string {
|
||||
// - `target` is the only parameter to this function (a configured target).
|
||||
// - The return value must be a string.
|
||||
// - The function body should not be indented outside of its own scope.
|
||||
func (g getOutputFilesAndCcObjectFilesType) StarlarkFunctionBody() string {
|
||||
func (g getCcInfoType) StarlarkFunctionBody() string {
|
||||
return `
|
||||
outputFiles = [f.path for f in target.files.to_list()]
|
||||
|
||||
ccObjectFiles = []
|
||||
staticLibraries = []
|
||||
linker_inputs = providers(target)["CcInfo"].linking_context.linker_inputs.to_list()
|
||||
|
||||
for linker_input in linker_inputs:
|
||||
for library in linker_input.libraries:
|
||||
for object in library.objects:
|
||||
ccObjectFiles += [object.path]
|
||||
return ', '.join(outputFiles) + "|" + ', '.join(ccObjectFiles)`
|
||||
if library.static_library:
|
||||
staticLibraries.append(library.static_library.path)
|
||||
|
||||
returns = [
|
||||
outputFiles,
|
||||
staticLibraries,
|
||||
ccObjectFiles,
|
||||
]
|
||||
|
||||
return "|".join([", ".join(r) for r in returns])`
|
||||
}
|
||||
|
||||
// ParseResult returns a value obtained by parsing the result of the request's Starlark function.
|
||||
// The given rawString must correspond to the string output which was created by evaluating the
|
||||
// Starlark given in StarlarkFunctionBody.
|
||||
func (g getOutputFilesAndCcObjectFilesType) ParseResult(rawString string) GetOutputFilesAndCcObjectFiles_Result {
|
||||
func (g getCcInfoType) ParseResult(rawString string) CcInfo {
|
||||
var outputFiles []string
|
||||
var ccObjects []string
|
||||
|
||||
splitString := strings.Split(rawString, "|")
|
||||
outputFilesString := splitString[0]
|
||||
ccObjectsString := splitString[1]
|
||||
ccStaticLibrariesString := splitString[1]
|
||||
ccObjectsString := splitString[2]
|
||||
outputFiles = splitOrEmpty(outputFilesString, ", ")
|
||||
ccStaticLibraries := splitOrEmpty(ccStaticLibrariesString, ", ")
|
||||
ccObjects = splitOrEmpty(ccObjectsString, ", ")
|
||||
return GetOutputFilesAndCcObjectFiles_Result{outputFiles, ccObjects}
|
||||
}
|
||||
|
||||
type getPrebuiltCcStaticLibraryFiles struct{}
|
||||
|
||||
// Name returns the name of the starlark function to get prebuilt cc static library files
|
||||
func (g getPrebuiltCcStaticLibraryFiles) Name() string {
|
||||
return "getPrebuiltCcStaticLibraryFiles"
|
||||
}
|
||||
|
||||
// StarlarkFunctionBody returns the unindented body of a starlark function for extracting the static
|
||||
// library paths from a cc_import module.
|
||||
func (g getPrebuiltCcStaticLibraryFiles) StarlarkFunctionBody() string {
|
||||
return `
|
||||
linker_inputs = providers(target)["CcInfo"].linking_context.linker_inputs.to_list()
|
||||
|
||||
static_libraries = []
|
||||
for linker_input in linker_inputs:
|
||||
for library in linker_input.libraries:
|
||||
static_libraries.append(library.static_library.path)
|
||||
|
||||
return ', '.join(static_libraries)`
|
||||
}
|
||||
|
||||
// ParseResult returns a slice of bazel output paths to static libraries if any exist for the given
|
||||
// rawString corresponding to the string output which was created by evaluating the
|
||||
// StarlarkFunctionBody.
|
||||
func (g getPrebuiltCcStaticLibraryFiles) ParseResult(rawString string) []string {
|
||||
return strings.Split(rawString, ", ")
|
||||
return CcInfo{
|
||||
OutputFiles: outputFiles,
|
||||
CcObjectFiles: ccObjects,
|
||||
CcStaticLibraryFiles: ccStaticLibraries,
|
||||
}
|
||||
}
|
||||
|
||||
// splitOrEmpty is a modification of strings.Split() that returns an empty list
|
||||
|
||||
Reference in New Issue
Block a user