From 796921d211f79e73c0c41352b3d6273d7bc92c37 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Tue, 11 Jul 2023 08:21:41 -0400 Subject: [PATCH] Ensure data is passed to all generation actions Test: go test genrule tests Test: build/soong/tests/genrule_sandbox_test.py \ framework-cppstream-protos framework-javastream-protos Change-Id: I16fa939280c7ff0f230a0a8cf18af5e55f16eb03 --- genrule/allowlists.go | 2 -- genrule/genrule.go | 2 +- genrule/genrule_test.go | 42 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/genrule/allowlists.go b/genrule/allowlists.go index 012c59c8d..22703fdfb 100644 --- a/genrule/allowlists.go +++ b/genrule/allowlists.go @@ -115,8 +115,6 @@ var ( "nos_app_weaver_service_genc++_headers", "nos_app_weaver_service_genc++_mock", "nos_generator_test_service_genc++", - "framework-cppstream-protos", - "framework-javastream-protos", "aidl_camera_build_version", "cronet_aml_base_android_runtime_unchecked_jni_headers", "cronet_aml_base_android_runtime_jni_headers", diff --git a/genrule/genrule.go b/genrule/genrule.go index b29e2c96a..99c91667c 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -435,6 +435,7 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) { cmd = g.CmdModifier(ctx, cmd) } + var extraInputs android.Paths // Generate tasks, either from genrule or gensrcs. for i, task := range g.taskGenerator(ctx, cmd, srcFiles) { if len(task.out) == 0 { @@ -442,7 +443,6 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) { return } - var extraInputs android.Paths // Only handle extra inputs once as these currently are the same across all tasks if i == 0 { for name, values := range task.extraInputs { diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go index 7c17db1be..6301bbf01 100644 --- a/genrule/genrule_test.go +++ b/genrule/genrule_test.go @@ -18,6 +18,7 @@ import ( "fmt" "os" "regexp" + "strconv" "testing" "android/soong/android" @@ -557,10 +558,12 @@ func TestGenSrcs(t *testing.T) { allowMissingDependencies bool - err string - cmds []string - deps []string - files []string + err string + cmds []string + deps []string + files []string + shards int + inputs []string }{ { name: "gensrcs", @@ -627,9 +630,29 @@ func TestGenSrcs(t *testing.T) { "out/soong/.intermediates/gen/gen/gensrcs/in2.h", "out/soong/.intermediates/gen/gen/gensrcs/in3.h", }, + shards: 2, + inputs: []string{ + "baz.txt", + }, }, } + checkInputs := func(t *testing.T, rule android.TestingBuildParams, inputs []string) { + t.Helper() + if len(inputs) == 0 { + return + } + inputBaseNames := map[string]bool{} + for _, f := range rule.Implicits { + inputBaseNames[f.Base()] = true + } + for _, f := range inputs { + if _, ok := inputBaseNames[f]; !ok { + t.Errorf("Expected to find input file %q for %q, but did not", f, rule.Description) + } + } + } + for _, test := range testcases { t.Run(test.name, func(t *testing.T) { bp := "gensrcs {\n" @@ -647,10 +670,21 @@ func TestGenSrcs(t *testing.T) { ExtendWithErrorHandler(android.FixtureExpectsAllErrorsToMatchAPattern(expectedErrors)). RunTestWithBp(t, testGenruleBp()+bp) + mod := result.ModuleForTests("gen", "") if expectedErrors != nil { return } + if test.shards > 0 { + for i := 0; i < test.shards; i++ { + r := mod.Rule("generator" + strconv.Itoa(i)) + checkInputs(t, r, test.inputs) + } + } else { + r := mod.Rule("generator") + checkInputs(t, r, test.inputs) + } + gen := result.Module("gen", "").(*Module) android.AssertDeepEquals(t, "cmd", test.cmds, gen.rawCommands)