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
diff --git a/genrule/allowlists.go b/genrule/allowlists.go
index 012c59c..22703fd 100644
--- a/genrule/allowlists.go
+++ b/genrule/allowlists.go
@@ -115,8 +115,6 @@
"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 b29e2c9..99c9166 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -435,6 +435,7 @@
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 @@
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 7c17db1..6301bbf 100644
--- a/genrule/genrule_test.go
+++ b/genrule/genrule_test.go
@@ -18,6 +18,7 @@
"fmt"
"os"
"regexp"
+ "strconv"
"testing"
"android/soong/android"
@@ -557,10 +558,12 @@
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 @@
"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 @@
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)