Use proto output instead of jsonproto output for aquery
Test: use m --bazel-mode-dev and mixed_droid.sh
Bug: 233798334
Change-Id: Ib945359d3d05e6f51afe70432ec380e4e584175b
diff --git a/android/bazel_handler.go b/android/bazel_handler.go
index f16ee60..e15a81e 100644
--- a/android/bazel_handler.go
+++ b/android/bazel_handler.go
@@ -558,7 +558,6 @@
// The actual platform values here may be overridden by configuration
// transitions from the buildroot.
fmt.Sprintf("--extra_toolchains=%s", "//prebuilts/clang/host/linux-x86:all"),
-
// This should be parameterized on the host OS, but let's restrict to linux
// to keep things simple for now.
fmt.Sprintf("--host_platform=%s", "//build/bazel/platforms:linux_x86_64"),
@@ -927,7 +926,7 @@
//
// Use jsonproto instead of proto; actual proto parsing would require a dependency on Bazel's
// proto sources, which would add a number of unnecessary dependencies.
- extraFlags := []string{"--output=jsonproto", "--include_file_write_contents"}
+ extraFlags := []string{"--output=proto", "--include_file_write_contents"}
if Bool(config.productVariables.ClangCoverage) {
extraFlags = append(extraFlags, "--collect_code_coverage")
paths := make([]string, 0, 2)
diff --git a/android/bazel_handler_test.go b/android/bazel_handler_test.go
index dc2261c..c857272 100644
--- a/android/bazel_handler_test.go
+++ b/android/bazel_handler_test.go
@@ -1,6 +1,7 @@
package android
import (
+ "encoding/json"
"os"
"path/filepath"
"reflect"
@@ -8,6 +9,8 @@
"testing"
"android/soong/bazel/cquery"
+ "google.golang.org/protobuf/proto"
+ analysis_v2_proto "prebuilts/bazel/common/proto/analysis_v2"
)
var testConfig = TestConfig("out", nil, "", nil)
@@ -65,52 +68,56 @@
var testCases = []testCase{
{`
{
- "artifacts": [
- { "id": 1, "pathFragmentId": 1 },
- { "id": 2, "pathFragmentId": 2 }],
- "actions": [{
- "targetId": 1,
- "actionKey": "x",
- "mnemonic": "x",
- "arguments": ["touch", "foo"],
- "inputDepSetIds": [1],
- "outputIds": [1],
- "primaryOutputId": 1
- }],
- "depSetOfFiles": [
- { "id": 1, "directArtifactIds": [1, 2] }],
- "pathFragments": [
- { "id": 1, "label": "one" },
- { "id": 2, "label": "two" }]
+ "artifacts": [
+ { "id": 1, "path_fragment_id": 1 },
+ { "id": 2, "path_fragment_id": 2 }],
+ "actions": [{
+ "target_Id": 1,
+ "action_Key": "x",
+ "mnemonic": "x",
+ "arguments": ["touch", "foo"],
+ "input_dep_set_ids": [1],
+ "output_Ids": [1],
+ "primary_output_id": 1
+ }],
+ "dep_set_of_files": [
+ { "id": 1, "direct_artifact_ids": [1, 2] }],
+ "path_fragments": [
+ { "id": 1, "label": "one" },
+ { "id": 2, "label": "two" }]
}`,
"cd 'test/exec_root' && rm -f 'one' && touch foo",
}, {`
{
- "artifacts": [
- { "id": 1, "pathFragmentId": 10 },
- { "id": 2, "pathFragmentId": 20 }],
- "actions": [{
- "targetId": 100,
- "actionKey": "x",
- "mnemonic": "x",
- "arguments": ["bogus", "command"],
- "outputIds": [1, 2],
- "primaryOutputId": 1
- }],
- "pathFragments": [
- { "id": 10, "label": "one", "parentId": 30 },
- { "id": 20, "label": "one.d", "parentId": 30 },
- { "id": 30, "label": "parent" }]
+ "artifacts": [
+ { "id": 1, "path_fragment_id": 10 },
+ { "id": 2, "path_fragment_id": 20 }],
+ "actions": [{
+ "target_Id": 100,
+ "action_Key": "x",
+ "mnemonic": "x",
+ "arguments": ["bogus", "command"],
+ "output_Ids": [1, 2],
+ "primary_output_id": 1
+ }],
+ "path_fragments": [
+ { "id": 10, "label": "one", "parent_id": 30 },
+ { "id": 20, "label": "one.d", "parent_id": 30 },
+ { "id": 30, "label": "parent" }]
}`,
`cd 'test/exec_root' && rm -f 'parent/one' && bogus command && sed -i'' -E 's@(^|\s|")bazel-out/@\1test/bazel_out/@g' 'parent/one.d'`,
},
}
for i, testCase := range testCases {
+ data, err := JsonToActionGraphContainer(testCase.input)
+ if err != nil {
+ t.Error(err)
+ }
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{
- bazelCommand{command: "aquery", expression: "deps(@soong_injection//mixed_builds:buildroot)"}: testCase.input})
+ bazelCommand{command: "aquery", expression: "deps(@soong_injection//mixed_builds:buildroot)"}: string(data)})
- err := bazelContext.InvokeBazel(testConfig)
+ err = bazelContext.InvokeBazel(testConfig)
if err != nil {
t.Fatalf("testCase #%d: did not expect error invoking Bazel, but got %s", i+1, err)
}
@@ -194,3 +201,14 @@
requests: map[cqueryKey]bool{},
}, p.soongOutDir
}
+
+// Transform the json format to ActionGraphContainer
+func JsonToActionGraphContainer(inputString string) ([]byte, error) {
+ var aqueryProtoResult analysis_v2_proto.ActionGraphContainer
+ err := json.Unmarshal([]byte(inputString), &aqueryProtoResult)
+ if err != nil {
+ return []byte(""), err
+ }
+ data, _ := proto.Marshal(&aqueryProtoResult)
+ return data, err
+}