Merge "Move cquery RequestType interface to bazel_handler"
This commit is contained in:
@@ -34,10 +34,26 @@ import (
|
|||||||
"android/soong/shared"
|
"android/soong/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type cqueryRequest interface {
|
||||||
|
// Name returns a string name for this request type. Such request type names must be unique,
|
||||||
|
// and must only consist of alphanumeric characters.
|
||||||
|
Name() string
|
||||||
|
|
||||||
|
// StarlarkFunctionBody returns a starlark function body to process this request type.
|
||||||
|
// The returned string is the body of a Starlark function which obtains
|
||||||
|
// all request-relevant information about a target and returns a string containing
|
||||||
|
// this information.
|
||||||
|
// The function should have the following properties:
|
||||||
|
// - `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.
|
||||||
|
StarlarkFunctionBody() string
|
||||||
|
}
|
||||||
|
|
||||||
// Map key to describe bazel cquery requests.
|
// Map key to describe bazel cquery requests.
|
||||||
type cqueryKey struct {
|
type cqueryKey struct {
|
||||||
label string
|
label string
|
||||||
requestType cquery.RequestType
|
requestType cqueryRequest
|
||||||
archType ArchType
|
archType ArchType
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +149,7 @@ func (bazelCtx *bazelContext) GetOutputFiles(label string, archType ArchType) ([
|
|||||||
var ret []string
|
var ret []string
|
||||||
if ok {
|
if ok {
|
||||||
bazelOutput := strings.TrimSpace(rawString)
|
bazelOutput := strings.TrimSpace(rawString)
|
||||||
ret = cquery.GetOutputFiles.ParseResult(bazelOutput).([]string)
|
ret = cquery.GetOutputFiles.ParseResult(bazelOutput)
|
||||||
}
|
}
|
||||||
return ret, ok
|
return ret, ok
|
||||||
}
|
}
|
||||||
@@ -145,7 +161,7 @@ func (bazelCtx *bazelContext) GetOutputFilesAndCcObjectFiles(label string, archT
|
|||||||
result, ok := bazelCtx.cquery(label, cquery.GetOutputFilesAndCcObjectFiles, archType)
|
result, ok := bazelCtx.cquery(label, cquery.GetOutputFilesAndCcObjectFiles, archType)
|
||||||
if ok {
|
if ok {
|
||||||
bazelOutput := strings.TrimSpace(result)
|
bazelOutput := strings.TrimSpace(result)
|
||||||
returnResult := cquery.GetOutputFilesAndCcObjectFiles.ParseResult(bazelOutput).(cquery.GetOutputFilesAndCcObjectFiles_Result)
|
returnResult := cquery.GetOutputFilesAndCcObjectFiles.ParseResult(bazelOutput)
|
||||||
outputFiles = returnResult.OutputFiles
|
outputFiles = returnResult.OutputFiles
|
||||||
ccObjects = returnResult.CcObjectFiles
|
ccObjects = returnResult.CcObjectFiles
|
||||||
}
|
}
|
||||||
@@ -231,7 +247,7 @@ func (context *bazelContext) BazelEnabled() bool {
|
|||||||
// If the given request was already made (and the results are available), then
|
// If the given request was already made (and the results are available), then
|
||||||
// returns (result, true). If the request is queued but no results are available,
|
// returns (result, true). If the request is queued but no results are available,
|
||||||
// then returns ("", false).
|
// then returns ("", false).
|
||||||
func (context *bazelContext) cquery(label string, requestType cquery.RequestType,
|
func (context *bazelContext) cquery(label string, requestType cqueryRequest,
|
||||||
archType ArchType) (string, bool) {
|
archType ArchType) (string, bool) {
|
||||||
key := cqueryKey{label, requestType, archType}
|
key := cqueryKey{label, requestType, archType}
|
||||||
if result, ok := context.results[key]; ok {
|
if result, ok := context.results[key]; ok {
|
||||||
@@ -449,7 +465,7 @@ func indent(original string) string {
|
|||||||
// and grouped by their request type. The data retrieved for each label depends on its
|
// and grouped by their request type. The data retrieved for each label depends on its
|
||||||
// request type.
|
// request type.
|
||||||
func (context *bazelContext) cqueryStarlarkFileContents() []byte {
|
func (context *bazelContext) cqueryStarlarkFileContents() []byte {
|
||||||
requestTypeToCqueryIdEntries := map[cquery.RequestType][]string{}
|
requestTypeToCqueryIdEntries := map[cqueryRequest][]string{}
|
||||||
for val, _ := range context.requests {
|
for val, _ := range context.requests {
|
||||||
cqueryId := getCqueryId(val)
|
cqueryId := getCqueryId(val)
|
||||||
mapEntryString := fmt.Sprintf("%q : True", cqueryId)
|
mapEntryString := fmt.Sprintf("%q : True", cqueryId)
|
||||||
|
@@ -5,8 +5,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
GetOutputFiles RequestType = &getOutputFilesRequestType{}
|
GetOutputFiles = &getOutputFilesRequestType{}
|
||||||
GetOutputFilesAndCcObjectFiles RequestType = &getOutputFilesAndCcObjectFilesType{}
|
GetOutputFilesAndCcObjectFiles = &getOutputFilesAndCcObjectFilesType{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetOutputFilesAndCcObjectFiles_Result struct {
|
type GetOutputFilesAndCcObjectFiles_Result struct {
|
||||||
@@ -14,49 +14,49 @@ type GetOutputFilesAndCcObjectFiles_Result struct {
|
|||||||
CcObjectFiles []string
|
CcObjectFiles []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type RequestType interface {
|
|
||||||
// Name returns a string name for this request type. Such request type names must be unique,
|
|
||||||
// and must only consist of alphanumeric characters.
|
|
||||||
Name() string
|
|
||||||
|
|
||||||
// StarlarkFunctionBody returns a straark function body to process this request type.
|
|
||||||
// The returned string is the body of a Starlark function which obtains
|
|
||||||
// all request-relevant information about a target and returns a string containing
|
|
||||||
// this information.
|
|
||||||
// The function should have the following properties:
|
|
||||||
// - `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.
|
|
||||||
StarlarkFunctionBody() string
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
// The type of this value depends on the request type; it is up to the caller to
|
|
||||||
// cast to the correct type.
|
|
||||||
ParseResult(rawString string) interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type getOutputFilesRequestType struct{}
|
type getOutputFilesRequestType 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 getOutputFilesRequestType) Name() string {
|
func (g getOutputFilesRequestType) Name() string {
|
||||||
return "getOutputFiles"
|
return "getOutputFiles"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StarlarkFunctionBody returns a starlark function body to process this request type.
|
||||||
|
// The returned string is the body of a Starlark function which obtains
|
||||||
|
// all request-relevant information about a target and returns a string containing
|
||||||
|
// this information.
|
||||||
|
// The function should have the following properties:
|
||||||
|
// - `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 getOutputFilesRequestType) StarlarkFunctionBody() string {
|
func (g getOutputFilesRequestType) StarlarkFunctionBody() string {
|
||||||
return "return ', '.join([f.path for f in target.files.to_list()])"
|
return "return ', '.join([f.path for f in target.files.to_list()])"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g getOutputFilesRequestType) ParseResult(rawString string) interface{} {
|
// 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 getOutputFilesRequestType) ParseResult(rawString string) []string {
|
||||||
return strings.Split(rawString, ", ")
|
return strings.Split(rawString, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
type getOutputFilesAndCcObjectFilesType struct{}
|
type getOutputFilesAndCcObjectFilesType 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 {
|
func (g getOutputFilesAndCcObjectFilesType) Name() string {
|
||||||
return "getOutputFilesAndCcObjectFiles"
|
return "getOutputFilesAndCcObjectFiles"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StarlarkFunctionBody returns a starlark function body to process this request type.
|
||||||
|
// The returned string is the body of a Starlark function which obtains
|
||||||
|
// all request-relevant information about a target and returns a string containing
|
||||||
|
// this information.
|
||||||
|
// The function should have the following properties:
|
||||||
|
// - `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 getOutputFilesAndCcObjectFilesType) StarlarkFunctionBody() string {
|
||||||
return `
|
return `
|
||||||
outputFiles = [f.path for f in target.files.to_list()]
|
outputFiles = [f.path for f in target.files.to_list()]
|
||||||
@@ -71,7 +71,10 @@ for linker_input in linker_inputs:
|
|||||||
return ', '.join(outputFiles) + "|" + ', '.join(ccObjectFiles)`
|
return ', '.join(outputFiles) + "|" + ', '.join(ccObjectFiles)`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g getOutputFilesAndCcObjectFilesType) ParseResult(rawString string) interface{} {
|
// 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 {
|
||||||
var outputFiles []string
|
var outputFiles []string
|
||||||
var ccObjects []string
|
var ccObjects []string
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user