Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab17626b authored by Jason Wu's avatar Jason Wu Committed by Gerrit Code Review
Browse files

Merge "Revert "Use proto output instead of jsonproto output for aquery""

parents b1bd4bf7 d27e28c2
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -558,6 +558,7 @@ func (r *builtinBazelRunner) createBazelCommand(paths *bazelPaths, runName bazel
		// 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"),
@@ -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
	// 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) {
		extraFlags = append(extraFlags, "--collect_code_coverage")
		paths := make([]string, 0, 2)
+34 −52
Original line number Diff line number Diff line
package android

import (
	"encoding/json"
	"os"
	"path/filepath"
	"reflect"
@@ -9,8 +8,6 @@ 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)
@@ -69,20 +66,20 @@ func TestInvokeBazelPopulatesBuildStatements(t *testing.T) {
		{`
{
  "artifacts": [
   { "id": 1, "path_fragment_id": 1 },
   { "id": 2, "path_fragment_id": 2 }],
    { "id": 1, "pathFragmentId": 1 },
    { "id": 2, "pathFragmentId": 2 }],
  "actions": [{
   "target_Id": 1,
   "action_Key": "x",
    "targetId": 1,
    "actionKey": "x",
    "mnemonic": "x",
    "arguments": ["touch", "foo"],
   "input_dep_set_ids": [1],
   "output_Ids": [1],
   "primary_output_id": 1
    "inputDepSetIds": [1],
    "outputIds": [1],
    "primaryOutputId": 1
  }],
 "dep_set_of_files": [
   { "id": 1, "direct_artifact_ids": [1, 2] }],
 "path_fragments": [
  "depSetOfFiles": [
    { "id": 1, "directArtifactIds": [1, 2] }],
  "pathFragments": [
    { "id": 1, "label": "one" },
    { "id": 2, "label": "two" }]
}`,
@@ -90,19 +87,19 @@ func TestInvokeBazelPopulatesBuildStatements(t *testing.T) {
		}, {`
{
  "artifacts": [
   { "id": 1, "path_fragment_id": 10 },
   { "id": 2, "path_fragment_id": 20 }],
    { "id": 1, "pathFragmentId": 10 },
    { "id": 2, "pathFragmentId": 20 }],
  "actions": [{
   "target_Id": 100,
   "action_Key": "x",
    "targetId": 100,
    "actionKey": "x",
    "mnemonic": "x",
    "arguments": ["bogus", "command"],
   "output_Ids": [1, 2],
   "primary_output_id": 1
    "outputIds": [1, 2],
    "primaryOutputId": 1
  }],
 "path_fragments": [
   { "id": 10, "label": "one", "parent_id": 30 },
   { "id": 20, "label": "one.d", "parent_id": 30 },
  "pathFragments": [
    { "id": 10, "label": "one", "parentId": 30 },
    { "id": 20, "label": "one.d", "parentId": 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'`,
@@ -110,14 +107,10 @@ func TestInvokeBazelPopulatesBuildStatements(t *testing.T) {
	}

	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)"}: 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 {
			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{},
	}, 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
}
+0 −1
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ bootstrap_go_package {
        "soong_build",
    ],
    deps: [
        "bazel_analysis_v2_proto",
        "blueprint",
    ],
}
+3 −72
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package bazel
import (
	"crypto/sha256"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"path/filepath"
	"reflect"
@@ -24,8 +25,6 @@ import (
	"strings"

	"github.com/google/blueprint/proptools"
	"google.golang.org/protobuf/proto"
	analysis_v2_proto "prebuilts/bazel/common/proto/analysis_v2"
)

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
// are one-to-one with Bazel's depSetOfFiles objects.
func AqueryBuildStatements(aqueryJsonProto []byte) ([]BuildStatement, []AqueryDepset, error) {
	aqueryProto := &analysis_v2_proto.ActionGraphContainer{}
	err := proto.Unmarshal(aqueryJsonProto, aqueryProto)
	var aqueryResult actionGraphContainer
	err := json.Unmarshal(aqueryJsonProto, &aqueryResult)
	if err != nil {
		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)
	if err != nil {
		return nil, nil, err
+527 −638

File changed.

Preview size limit exceeded, changes collapsed.

Loading