Move cquery RequestType interface to bazel_handler
go idiom is to define the interface where it is used rather than where
it is defined. This makes it obvious that ParseResult is not a used part
of the interface, removing the need to return an interface{} and cast
results.
Test: go test soong tests
Test: generate & sync bp2build; mixed build libc
Change-Id: I0d8d99c1d8d0125588522cc86502286b83c91bf7
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index 5b9d3bf..5ac6924 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -34,10 +34,26 @@
"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.
type cqueryKey struct {
label string
- requestType cquery.RequestType
+ requestType cqueryRequest
archType ArchType
}
@@ -133,7 +149,7 @@
var ret []string
if ok {
bazelOutput := strings.TrimSpace(rawString)
- ret = cquery.GetOutputFiles.ParseResult(bazelOutput).([]string)
+ ret = cquery.GetOutputFiles.ParseResult(bazelOutput)
}
return ret, ok
}
@@ -145,7 +161,7 @@
result, ok := bazelCtx.cquery(label, cquery.GetOutputFilesAndCcObjectFiles, archType)
if ok {
bazelOutput := strings.TrimSpace(result)
- returnResult := cquery.GetOutputFilesAndCcObjectFiles.ParseResult(bazelOutput).(cquery.GetOutputFilesAndCcObjectFiles_Result)
+ returnResult := cquery.GetOutputFilesAndCcObjectFiles.ParseResult(bazelOutput)
outputFiles = returnResult.OutputFiles
ccObjects = returnResult.CcObjectFiles
}
@@ -231,7 +247,7 @@
// 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,
// then returns ("", false).
-func (context *bazelContext) cquery(label string, requestType cquery.RequestType,
+func (context *bazelContext) cquery(label string, requestType cqueryRequest,
archType ArchType) (string, bool) {
key := cqueryKey{label, requestType, archType}
if result, ok := context.results[key]; ok {
@@ -449,7 +465,7 @@
// and grouped by their request type. The data retrieved for each label depends on its
// request type.
func (context *bazelContext) cqueryStarlarkFileContents() []byte {
- requestTypeToCqueryIdEntries := map[cquery.RequestType][]string{}
+ requestTypeToCqueryIdEntries := map[cqueryRequest][]string{}
for val, _ := range context.requests {
cqueryId := getCqueryId(val)
mapEntryString := fmt.Sprintf("%q : True", cqueryId)