Revert "Use proto output instead of jsonproto output for aquery"
This reverts commit 6fe8721e12
.
Reason for revert: Broke aosp_kernel-build-tools/linux
Change-Id: I502ec4c275cbc56e1024a42fadf68b308750939d
This commit is contained in:
committed by
Christopher Parsons
parent
6fe8721e12
commit
d27e28c2a7
@@ -558,6 +558,7 @@ func (r *builtinBazelRunner) createBazelCommand(paths *bazelPaths, runName bazel
|
|||||||
// The actual platform values here may be overridden by configuration
|
// The actual platform values here may be overridden by configuration
|
||||||
// transitions from the buildroot.
|
// transitions from the buildroot.
|
||||||
fmt.Sprintf("--extra_toolchains=%s", "//prebuilts/clang/host/linux-x86:all"),
|
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
|
// This should be parameterized on the host OS, but let's restrict to linux
|
||||||
// to keep things simple for now.
|
// to keep things simple for now.
|
||||||
fmt.Sprintf("--host_platform=%s", "//build/bazel/platforms:linux_x86_64"),
|
fmt.Sprintf("--host_platform=%s", "//build/bazel/platforms:linux_x86_64"),
|
||||||
@@ -926,7 +927,7 @@ func (context *bazelContext) InvokeBazel(config Config) error {
|
|||||||
//
|
//
|
||||||
// Use jsonproto instead of proto; actual proto parsing would require a dependency on Bazel's
|
// 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.
|
// proto sources, which would add a number of unnecessary dependencies.
|
||||||
extraFlags := []string{"--output=proto", "--include_file_write_contents"}
|
extraFlags := []string{"--output=jsonproto", "--include_file_write_contents"}
|
||||||
if Bool(config.productVariables.ClangCoverage) {
|
if Bool(config.productVariables.ClangCoverage) {
|
||||||
extraFlags = append(extraFlags, "--collect_code_coverage")
|
extraFlags = append(extraFlags, "--collect_code_coverage")
|
||||||
paths := make([]string, 0, 2)
|
paths := make([]string, 0, 2)
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package android
|
package android
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -9,8 +8,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"android/soong/bazel/cquery"
|
"android/soong/bazel/cquery"
|
||||||
"google.golang.org/protobuf/proto"
|
|
||||||
analysis_v2_proto "prebuilts/bazel/common/proto/analysis_v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var testConfig = TestConfig("out", nil, "", nil)
|
var testConfig = TestConfig("out", nil, "", nil)
|
||||||
@@ -68,56 +65,52 @@ func TestInvokeBazelPopulatesBuildStatements(t *testing.T) {
|
|||||||
var testCases = []testCase{
|
var testCases = []testCase{
|
||||||
{`
|
{`
|
||||||
{
|
{
|
||||||
"artifacts": [
|
"artifacts": [
|
||||||
{ "id": 1, "path_fragment_id": 1 },
|
{ "id": 1, "pathFragmentId": 1 },
|
||||||
{ "id": 2, "path_fragment_id": 2 }],
|
{ "id": 2, "pathFragmentId": 2 }],
|
||||||
"actions": [{
|
"actions": [{
|
||||||
"target_Id": 1,
|
"targetId": 1,
|
||||||
"action_Key": "x",
|
"actionKey": "x",
|
||||||
"mnemonic": "x",
|
"mnemonic": "x",
|
||||||
"arguments": ["touch", "foo"],
|
"arguments": ["touch", "foo"],
|
||||||
"input_dep_set_ids": [1],
|
"inputDepSetIds": [1],
|
||||||
"output_Ids": [1],
|
"outputIds": [1],
|
||||||
"primary_output_id": 1
|
"primaryOutputId": 1
|
||||||
}],
|
}],
|
||||||
"dep_set_of_files": [
|
"depSetOfFiles": [
|
||||||
{ "id": 1, "direct_artifact_ids": [1, 2] }],
|
{ "id": 1, "directArtifactIds": [1, 2] }],
|
||||||
"path_fragments": [
|
"pathFragments": [
|
||||||
{ "id": 1, "label": "one" },
|
{ "id": 1, "label": "one" },
|
||||||
{ "id": 2, "label": "two" }]
|
{ "id": 2, "label": "two" }]
|
||||||
}`,
|
}`,
|
||||||
"cd 'test/exec_root' && rm -f 'one' && touch foo",
|
"cd 'test/exec_root' && rm -f 'one' && touch foo",
|
||||||
}, {`
|
}, {`
|
||||||
{
|
{
|
||||||
"artifacts": [
|
"artifacts": [
|
||||||
{ "id": 1, "path_fragment_id": 10 },
|
{ "id": 1, "pathFragmentId": 10 },
|
||||||
{ "id": 2, "path_fragment_id": 20 }],
|
{ "id": 2, "pathFragmentId": 20 }],
|
||||||
"actions": [{
|
"actions": [{
|
||||||
"target_Id": 100,
|
"targetId": 100,
|
||||||
"action_Key": "x",
|
"actionKey": "x",
|
||||||
"mnemonic": "x",
|
"mnemonic": "x",
|
||||||
"arguments": ["bogus", "command"],
|
"arguments": ["bogus", "command"],
|
||||||
"output_Ids": [1, 2],
|
"outputIds": [1, 2],
|
||||||
"primary_output_id": 1
|
"primaryOutputId": 1
|
||||||
}],
|
}],
|
||||||
"path_fragments": [
|
"pathFragments": [
|
||||||
{ "id": 10, "label": "one", "parent_id": 30 },
|
{ "id": 10, "label": "one", "parentId": 30 },
|
||||||
{ "id": 20, "label": "one.d", "parent_id": 30 },
|
{ "id": 20, "label": "one.d", "parentId": 30 },
|
||||||
{ "id": 30, "label": "parent" }]
|
{ "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'`,
|
`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 {
|
for i, testCase := range testCases {
|
||||||
data, err := JsonToActionGraphContainer(testCase.input)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{
|
bazelContext, _ := testBazelContext(t, map[bazelCommand]string{
|
||||||
bazelCommand{command: "aquery", expression: "deps(@soong_injection//mixed_builds:buildroot)"}: string(data)})
|
bazelCommand{command: "aquery", expression: "deps(@soong_injection//mixed_builds:buildroot)"}: testCase.input})
|
||||||
|
|
||||||
err = bazelContext.InvokeBazel(testConfig)
|
err := bazelContext.InvokeBazel(testConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("testCase #%d: did not expect error invoking Bazel, but got %s", i+1, err)
|
t.Fatalf("testCase #%d: did not expect error invoking Bazel, but got %s", i+1, err)
|
||||||
}
|
}
|
||||||
@@ -201,14 +194,3 @@ func testBazelContext(t *testing.T, bazelCommandResults map[bazelCommand]string)
|
|||||||
requests: map[cqueryKey]bool{},
|
requests: map[cqueryKey]bool{},
|
||||||
}, p.soongOutDir
|
}, 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
|
|
||||||
}
|
|
||||||
|
@@ -20,7 +20,6 @@ bootstrap_go_package {
|
|||||||
"soong_build",
|
"soong_build",
|
||||||
],
|
],
|
||||||
deps: [
|
deps: [
|
||||||
"bazel_analysis_v2_proto",
|
|
||||||
"blueprint",
|
"blueprint",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ package bazel
|
|||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -24,8 +25,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
"google.golang.org/protobuf/proto"
|
|
||||||
analysis_v2_proto "prebuilts/bazel/common/proto/analysis_v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type artifactId int
|
type artifactId int
|
||||||
@@ -313,79 +312,11 @@ func (a *aqueryArtifactHandler) artifactPathsFromDepsetHash(depsetHash string) (
|
|||||||
// BuildStatements are one-to-one with actions in the given action graph, and AqueryDepsets
|
// BuildStatements are one-to-one with actions in the given action graph, and AqueryDepsets
|
||||||
// are one-to-one with Bazel's depSetOfFiles objects.
|
// are one-to-one with Bazel's depSetOfFiles objects.
|
||||||
func AqueryBuildStatements(aqueryJsonProto []byte) ([]BuildStatement, []AqueryDepset, error) {
|
func AqueryBuildStatements(aqueryJsonProto []byte) ([]BuildStatement, []AqueryDepset, error) {
|
||||||
aqueryProto := &analysis_v2_proto.ActionGraphContainer{}
|
var aqueryResult actionGraphContainer
|
||||||
err := proto.Unmarshal(aqueryJsonProto, aqueryProto)
|
err := json.Unmarshal(aqueryJsonProto, &aqueryResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
aqueryResult := actionGraphContainer{}
|
|
||||||
|
|
||||||
for _, protoArtifact := range aqueryProto.Artifacts {
|
|
||||||
aqueryResult.Artifacts = append(aqueryResult.Artifacts, artifact{artifactId(protoArtifact.Id),
|
|
||||||
pathFragmentId(protoArtifact.PathFragmentId)})
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, protoAction := range aqueryProto.Actions {
|
|
||||||
var environmentVariable []KeyValuePair
|
|
||||||
var inputDepSetIds []depsetId
|
|
||||||
var outputIds []artifactId
|
|
||||||
var substitutions []KeyValuePair
|
|
||||||
|
|
||||||
for _, protoEnvironmentVariable := range protoAction.EnvironmentVariables {
|
|
||||||
environmentVariable = append(environmentVariable, KeyValuePair{
|
|
||||||
protoEnvironmentVariable.Key, protoEnvironmentVariable.Value,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
for _, protoInputDepSetIds := range protoAction.InputDepSetIds {
|
|
||||||
inputDepSetIds = append(inputDepSetIds, depsetId(protoInputDepSetIds))
|
|
||||||
}
|
|
||||||
for _, protoOutputIds := range protoAction.OutputIds {
|
|
||||||
outputIds = append(outputIds, artifactId(protoOutputIds))
|
|
||||||
}
|
|
||||||
for _, protoSubstitutions := range protoAction.Substitutions {
|
|
||||||
substitutions = append(substitutions, KeyValuePair{
|
|
||||||
protoSubstitutions.Key, protoSubstitutions.Value,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
aqueryResult.Actions = append(aqueryResult.Actions,
|
|
||||||
action{
|
|
||||||
Arguments: protoAction.Arguments,
|
|
||||||
EnvironmentVariables: environmentVariable,
|
|
||||||
InputDepSetIds: inputDepSetIds,
|
|
||||||
Mnemonic: protoAction.Mnemonic,
|
|
||||||
OutputIds: outputIds,
|
|
||||||
TemplateContent: protoAction.TemplateContent,
|
|
||||||
Substitutions: substitutions,
|
|
||||||
FileContents: protoAction.FileContents})
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, protoDepSetOfFiles := range aqueryProto.DepSetOfFiles {
|
|
||||||
var directArtifactIds []artifactId
|
|
||||||
var transitiveDepSetIds []depsetId
|
|
||||||
|
|
||||||
for _, protoDirectArtifactIds := range protoDepSetOfFiles.DirectArtifactIds {
|
|
||||||
directArtifactIds = append(directArtifactIds, artifactId(protoDirectArtifactIds))
|
|
||||||
}
|
|
||||||
for _, protoTransitiveDepSetIds := range protoDepSetOfFiles.TransitiveDepSetIds {
|
|
||||||
transitiveDepSetIds = append(transitiveDepSetIds, depsetId(protoTransitiveDepSetIds))
|
|
||||||
}
|
|
||||||
aqueryResult.DepSetOfFiles = append(aqueryResult.DepSetOfFiles,
|
|
||||||
depSetOfFiles{
|
|
||||||
Id: depsetId(protoDepSetOfFiles.Id),
|
|
||||||
DirectArtifactIds: directArtifactIds,
|
|
||||||
TransitiveDepSetIds: transitiveDepSetIds})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, protoPathFragments := range aqueryProto.PathFragments {
|
|
||||||
aqueryResult.PathFragments = append(aqueryResult.PathFragments,
|
|
||||||
pathFragment{
|
|
||||||
Id: pathFragmentId(protoPathFragments.Id),
|
|
||||||
Label: protoPathFragments.Label,
|
|
||||||
ParentId: pathFragmentId(protoPathFragments.ParentId)})
|
|
||||||
|
|
||||||
}
|
|
||||||
aqueryHandler, err := newAqueryHandler(aqueryResult)
|
aqueryHandler, err := newAqueryHandler(aqueryResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
1165
bazel/aquery_test.go
1165
bazel/aquery_test.go
File diff suppressed because it is too large
Load Diff
9
go.mod
9
go.mod
@@ -13,12 +13,7 @@ exclude github.com/golang/protobuf v1.5.0
|
|||||||
|
|
||||||
replace github.com/google/go-cmp v0.5.5 => ../../external/go-cmp
|
replace github.com/google/go-cmp v0.5.5 => ../../external/go-cmp
|
||||||
|
|
||||||
require prebuilts/bazel/common/proto/analysis_v2 v0.0.0
|
// Indirect dep from go-cmp
|
||||||
|
exclude golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
|
||||||
replace prebuilts/bazel/common/proto/analysis_v2 => ../../prebuilts/bazel/common/proto/analysis_v2
|
|
||||||
|
|
||||||
require prebuilts/bazel/common/proto/build v0.0.0 // indirect
|
|
||||||
|
|
||||||
replace prebuilts/bazel/common/proto/build => ../../prebuilts/bazel/common/proto/build
|
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
@@ -85,7 +85,6 @@ function create_mock_soong {
|
|||||||
copy_directory build/blueprint
|
copy_directory build/blueprint
|
||||||
copy_directory build/soong
|
copy_directory build/soong
|
||||||
copy_directory build/make/tools/rbcrun
|
copy_directory build/make/tools/rbcrun
|
||||||
copy_directory prebuilts/bazel/common/proto
|
|
||||||
|
|
||||||
symlink_directory prebuilts/sdk
|
symlink_directory prebuilts/sdk
|
||||||
symlink_directory prebuilts/go
|
symlink_directory prebuilts/go
|
||||||
|
Reference in New Issue
Block a user