Use proto output instead of jsonproto output for aquery

Test: use m --bazel-mode-dev and mixed_droid.sh
Bug: 233798334
Change-Id: Ib945359d3d05e6f51afe70432ec380e4e584175b
This commit is contained in:
Jason Wu
2022-10-21 02:57:41 -04:00
parent 706d35fe7c
commit 6fe8721e12
7 changed files with 772 additions and 568 deletions

View File

@@ -1,6 +1,7 @@
package android
import (
"encoding/json"
"os"
"path/filepath"
"reflect"
@@ -8,6 +9,8 @@ import (
"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 @@ func TestInvokeBazelPopulatesBuildStatements(t *testing.T) {
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 @@ func testBazelContext(t *testing.T, bazelCommandResults map[bazelCommand]string)
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
}