aboutsummaryrefslogtreecommitdiff
path: root/bazel
diff options
context:
space:
mode:
authorChristopher Parsons <cparsons@google.com>2021-03-16 21:12:01 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-03-16 21:12:01 +0000
commitbc3f7e027681a2db8c546b53df7f81cf5d0d46b2 (patch)
tree2364d8cefd8c4713c1de0539ebee98eb83072a33 /bazel
parent8974f1706e2110d749b003f60974434c592b8ab5 (diff)
parent944e7d01aa30b720af6a6f39a06fa786f096226d (diff)
downloadsoong-bc3f7e027681a2db8c546b53df7f81cf5d0d46b2.tar.gz
Merge "Refactor and cleanup of cquery processing"
Diffstat (limited to 'bazel')
-rw-r--r--bazel/cquery/Android.bp14
-rw-r--r--bazel/cquery/request_type.go110
2 files changed, 124 insertions, 0 deletions
diff --git a/bazel/cquery/Android.bp b/bazel/cquery/Android.bp
new file mode 100644
index 000000000..3a71e9c1d
--- /dev/null
+++ b/bazel/cquery/Android.bp
@@ -0,0 +1,14 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+bootstrap_go_package {
+ name: "soong-cquery",
+ pkgPath: "android/soong/bazel/cquery",
+ srcs: [
+ "request_type.go",
+ ],
+ pluginFor: [
+ "soong_build",
+ ],
+}
diff --git a/bazel/cquery/request_type.go b/bazel/cquery/request_type.go
new file mode 100644
index 000000000..864db3d2d
--- /dev/null
+++ b/bazel/cquery/request_type.go
@@ -0,0 +1,110 @@
+package cquery
+
+import (
+ "strings"
+)
+
+var (
+ GetOutputFiles RequestType = &getOutputFilesRequestType{}
+ GetCcObjectFiles RequestType = &getCcObjectFilesRequestType{}
+ GetOutputFilesAndCcObjectFiles RequestType = &getOutputFilesAndCcObjectFilesType{}
+)
+
+type GetOutputFilesAndCcObjectFiles_Result struct {
+ OutputFiles []string
+ CcObjectFiles []string
+}
+
+var RequestTypes []RequestType = []RequestType{
+ GetOutputFiles, GetCcObjectFiles, GetOutputFilesAndCcObjectFiles}
+
+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{}
+
+func (g getOutputFilesRequestType) Name() string {
+ return "getOutputFiles"
+}
+
+func (g getOutputFilesRequestType) StarlarkFunctionBody() string {
+ return "return ', '.join([f.path for f in target.files.to_list()])"
+}
+
+func (g getOutputFilesRequestType) ParseResult(rawString string) interface{} {
+ return strings.Split(rawString, ", ")
+}
+
+type getCcObjectFilesRequestType struct{}
+
+func (g getCcObjectFilesRequestType) Name() string {
+ return "getCcObjectFiles"
+}
+
+func (g getCcObjectFilesRequestType) StarlarkFunctionBody() string {
+ return `
+result = []
+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:
+ result += [object.path]
+return ', '.join(result)`
+}
+
+func (g getCcObjectFilesRequestType) ParseResult(rawString string) interface{} {
+ return strings.Split(rawString, ", ")
+}
+
+type getOutputFilesAndCcObjectFilesType struct{}
+
+func (g getOutputFilesAndCcObjectFilesType) Name() string {
+ return "getOutputFilesAndCcObjectFiles"
+}
+
+func (g getOutputFilesAndCcObjectFilesType) StarlarkFunctionBody() string {
+ return `
+outputFiles = [f.path for f in target.files.to_list()]
+
+ccObjectFiles = []
+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)`
+}
+
+func (g getOutputFilesAndCcObjectFilesType) ParseResult(rawString string) interface{} {
+ var outputFiles []string
+ var ccObjects []string
+
+ splitString := strings.Split(rawString, "|")
+ outputFilesString := splitString[0]
+ ccObjectsString := splitString[1]
+ outputFiles = strings.Split(outputFilesString, ", ")
+ ccObjects = strings.Split(ccObjectsString, ", ")
+ return GetOutputFilesAndCcObjectFiles_Result{outputFiles, ccObjects}
+}