diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go index cd941ccbc..63f8fa9b8 100644 --- a/genrule/genrule_test.go +++ b/genrule/genrule_test.go @@ -790,6 +790,94 @@ func TestGenruleOutputFiles(t *testing.T) { result.ModuleForTests("gen_all", "").Module().(*useSource).srcs) } +func TestGenSrcsWithNonRootAndroidBpOutputFiles(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForGenRuleTest, + android.FixtureMergeMockFs(android.MockFS{ + "external-protos/path/Android.bp": []byte(` + filegroup { + name: "external-protos", + srcs: ["baz/baz.proto", "bar.proto"], + } + `), + "package-dir/Android.bp": []byte(` + gensrcs { + name: "module-name", + cmd: "mkdir -p $(genDir) && cat $(in) >> $(genDir)/$(out)", + srcs: [ + "src/foo.proto", + ":external-protos", + ], + output_extension: "proto.h", + } + `), + }), + ).RunTest(t) + + exportedIncludeDir := "out/soong/.intermediates/package-dir/module-name/gen/gensrcs" + gen := result.Module("module-name", "").(*Module) + + android.AssertPathsRelativeToTopEquals( + t, + "include path", + []string{exportedIncludeDir}, + gen.exportedIncludeDirs, + ) + android.AssertPathsRelativeToTopEquals( + t, + "files", + []string{ + exportedIncludeDir + "/package-dir/src/foo.proto.h", + exportedIncludeDir + "/external-protos/path/baz/baz.proto.h", + exportedIncludeDir + "/external-protos/path/bar.proto.h", + }, + gen.outputFiles, + ) +} + +func TestGenSrcsWithSrcsFromExternalPackage(t *testing.T) { + bp := ` + gensrcs { + name: "module-name", + cmd: "mkdir -p $(genDir) && cat $(in) >> $(genDir)/$(out)", + srcs: [ + ":external-protos", + ], + output_extension: "proto.h", + } + ` + result := android.GroupFixturePreparers( + prepareForGenRuleTest, + android.FixtureMergeMockFs(android.MockFS{ + "external-protos/path/Android.bp": []byte(` + filegroup { + name: "external-protos", + srcs: ["foo/foo.proto", "bar.proto"], + } + `), + }), + ).RunTestWithBp(t, bp) + + exportedIncludeDir := "out/soong/.intermediates/module-name/gen/gensrcs" + gen := result.Module("module-name", "").(*Module) + + android.AssertPathsRelativeToTopEquals( + t, + "include path", + []string{exportedIncludeDir}, + gen.exportedIncludeDirs, + ) + android.AssertPathsRelativeToTopEquals( + t, + "files", + []string{ + exportedIncludeDir + "/external-protos/path/foo/foo.proto.h", + exportedIncludeDir + "/external-protos/path/bar.proto.h", + }, + gen.outputFiles, + ) +} + func TestPrebuiltTool(t *testing.T) { testcases := []struct { name string