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

Commit 67007248 authored by kgui's avatar kgui
Browse files

Add new file name to output inputs/outputs of actions of modules into a new...

Add new file name to output inputs/outputs of actions of modules into a new file when `m json-module-graph` is executed.

And also delete the logic in droidstubs to output JSONDataActions.

Test: local.

Change-Id: Ib5d6f1f69c16c41f128e481131775c7699f96464
parent c7afdefa
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ var (
	delvePath   string

	moduleGraphFile   string
	moduleActionsFile string
	docFile           string
	bazelQueryViewDir string
	bp2buildMarker    string
@@ -76,6 +77,7 @@ func init() {

	// Flags representing various modes soong_build can run in
	flag.StringVar(&moduleGraphFile, "module_graph_file", "", "JSON module graph file to output")
	flag.StringVar(&moduleActionsFile, "module_actions_file", "", "JSON file to output inputs/outputs of actions of modules")
	flag.StringVar(&docFile, "soong_docs", "", "build documentation file to output")
	flag.StringVar(&bazelQueryViewDir, "bazel_queryview_dir", "", "path to the bazel queryview directory relative to --top")
	flag.StringVar(&bp2buildMarker, "bp2build_marker", "", "If set, run bp2build, touch the specified marker file then exit")
@@ -176,15 +178,17 @@ func writeMetrics(configuration android.Config) {
	}
}

func writeJsonModuleGraph(ctx *android.Context, path string) {
	f, err := os.Create(shared.JoinPath(topDir, path))
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s", err)
func writeJsonModuleGraphAndActions(ctx *android.Context, graphPath string, actionsPath string) {
	graphFile, graphErr := os.Create(shared.JoinPath(topDir, graphPath))
	actionsFile, actionsErr := os.Create(shared.JoinPath(topDir, actionsPath))
	if graphErr != nil || actionsErr != nil {
		fmt.Fprintf(os.Stderr, "Graph err: %s, actions err: %s", graphErr, actionsErr)
		os.Exit(1)
	}

	defer f.Close()
	ctx.Context.PrintJSONGraph(f)
	defer graphFile.Close()
	defer actionsFile.Close()
	ctx.Context.PrintJSONGraphAndActions(graphFile, actionsFile)
}

func writeBuildGlobsNinjaFile(srcDir, buildDir string, globs func() pathtools.MultipleGlobResults, config interface{}) []string {
@@ -254,7 +258,7 @@ func doChosenActivity(configuration android.Config, extraNinjaDeps []string) str
			writeDepFile(queryviewMarkerFile, ninjaDeps)
			return queryviewMarkerFile
		} else if generateModuleGraphFile {
			writeJsonModuleGraph(ctx, moduleGraphFile)
			writeJsonModuleGraphAndActions(ctx, moduleGraphFile, moduleActionsFile)
			writeDepFile(moduleGraphFile, ninjaDeps)
			return moduleGraphFile
		} else if generateDocFile {
+1 −16
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ import (
	"path/filepath"
	"strings"

	"github.com/google/blueprint"
	"github.com/google/blueprint/proptools"

	"android/soong/android"
@@ -808,7 +807,6 @@ type PrebuiltStubsSources struct {
	properties PrebuiltStubsSourcesProperties

	stubsSrcJar android.Path
	jsonDataActions []blueprint.JSONDataAction
}

func (p *PrebuiltStubsSources) OutputFiles(tag string) (android.Paths, error) {
@@ -824,13 +822,6 @@ func (d *PrebuiltStubsSources) StubsSrcJar() android.Path {
	return d.stubsSrcJar
}

// AddJSONData is a temporary solution for droidstubs module to put action
// related data into the module json graph.
func (p *PrebuiltStubsSources) AddJSONData(d *map[string]interface{}) {
	p.ModuleBase.AddJSONData(d)
	(*d)["Actions"] = blueprint.FormatJSONDataActions(p.jsonDataActions)
}

func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	if len(p.properties.Srcs) != 1 {
		ctx.PropertyErrorf("srcs", "must only specify one directory path or srcjar, contains %d paths", len(p.properties.Srcs))
@@ -838,12 +829,9 @@ func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleCon
	}

	src := p.properties.Srcs[0]
	var jsonDataAction blueprint.JSONDataAction
	if filepath.Ext(src) == ".srcjar" {
		// This is a srcjar. We can use it directly.
		p.stubsSrcJar = android.PathForModuleSrc(ctx, src)
		jsonDataAction.Inputs = []string{src}
		jsonDataAction.Outputs = []string{src}
	} else {
		outPath := android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar")

@@ -867,10 +855,7 @@ func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleCon
		rule.Restat()
		rule.Build("zip src", "Create srcjar from prebuilt source")
		p.stubsSrcJar = outPath
		jsonDataAction.Inputs = srcPaths.Strings()
		jsonDataAction.Outputs = []string{outPath.String()}
	}
	p.jsonDataActions = []blueprint.JSONDataAction{jsonDataAction}
}

func (p *PrebuiltStubsSources) Prebuilt() *android.Prebuilt {
+0 −23
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@ import (
	"strings"
	"testing"

	"github.com/google/blueprint"

	"android/soong/android"
)

@@ -234,27 +232,6 @@ func TestDroidstubsWithSystemModules(t *testing.T) {
	checkSystemModulesUseByDroidstubs(t, ctx, "stubs-prebuilt-system-modules", "prebuilt-jar.jar")
}

func TestAddJSONData(t *testing.T) {
	prebuiltStubsSources := PrebuiltStubsSources{}
	prebuiltStubsSources.jsonDataActions = []blueprint.JSONDataAction{
		blueprint.JSONDataAction{
			Inputs:  []string{},
			Outputs: []string{},
		},
	}
	jsonData := map[string]interface{}{}
	prebuiltStubsSources.AddJSONData(&jsonData)
	expectedOut := []map[string]interface{}{
		map[string]interface{}{
			"Inputs":  []string{},
			"Outputs": []string{},
		},
	}
	if !reflect.DeepEqual(jsonData["Actions"], expectedOut) {
		t.Errorf("The JSON action data %#v isn't as expected %#v.", jsonData["Actions"], expectedOut)
	}
}

func checkSystemModulesUseByDroidstubs(t *testing.T, ctx *android.TestContext, moduleName string, systemJar string) {
	metalavaRule := ctx.ModuleForTests(moduleName, "android_common").Rule("metalava")
	var systemJars []string
+4 −0
Original line number Diff line number Diff line
@@ -818,6 +818,10 @@ func (c *configImpl) ModuleGraphFile() string {
	return shared.JoinPath(c.SoongOutDir(), "module-graph.json")
}

func (c *configImpl) ModuleActionsFile() string {
	return shared.JoinPath(c.SoongOutDir(), "module-actions.json")
}

func (c *configImpl) TempDir() string {
	return shared.TempDirForOutDir(c.SoongOutDir())
}
+1 −0
Original line number Diff line number Diff line
@@ -284,6 +284,7 @@ func bootstrapBlueprint(ctx Context, config Config) {
		config.ModuleGraphFile(),
		[]string{
			"--module_graph_file", config.ModuleGraphFile(),
			"--module_actions_file", config.ModuleActionsFile(),
		},
		fmt.Sprintf("generating the Soong module graph at %s", config.ModuleGraphFile()),
	)