From d38c87c035ee267a76e1cf1a32d76756346e5679 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Mon, 17 Jul 2023 09:58:50 -0400 Subject: [PATCH] Make genrule export_include_dirs more consistent Previously, genrule export_include_dirs always added ModuleDir to exported include dirs when export_include_dirs is set but not when export_include_dirs is not set. Now when export_include_dirs is set, we also export the directory without the additional ModuleDir subdir. Test: genrule go tests Test: set export_include_dirs and test Change-Id: I46e860b2c20c1a96bddd14367d7fa737d901994d --- genrule/genrule.go | 3 +++ genrule/genrule_test.go | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/genrule/genrule.go b/genrule/genrule.go index b29e2c96a..530079ddd 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -293,6 +293,9 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) { for _, dir := range g.properties.Export_include_dirs { g.exportedIncludeDirs = append(g.exportedIncludeDirs, android.PathForModuleGen(ctx, g.subDir, ctx.ModuleDir(), dir)) + // Also export without ModuleDir for consistency with Export_include_dirs not being set + g.exportedIncludeDirs = append(g.exportedIncludeDirs, + android.PathForModuleGen(ctx, g.subDir, dir)) } } else { g.exportedIncludeDirs = append(g.exportedIncludeDirs, android.PathForModuleGen(ctx, g.subDir)) diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go index 7c17db1be..387a0f94b 100644 --- a/genrule/genrule_test.go +++ b/genrule/genrule_test.go @@ -811,6 +811,49 @@ func TestGenruleOutputFiles(t *testing.T) { result.ModuleForTests("gen_all", "").Module().(*useSource).srcs) } +func TestGenruleInterface(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForGenRuleTest, + android.FixtureMergeMockFs(android.MockFS{ + "package-dir/Android.bp": []byte(` + genrule { + name: "module-name", + cmd: "mkdir -p $(genDir) && cat $(in) >> $(genDir)/$(out)", + srcs: [ + "src/foo.proto", + ], + out: ["proto.h", "bar/proto.h"], + export_include_dirs: [".", "bar"], + } + `), + }), + ).RunTest(t) + + exportedIncludeDirs := []string{ + "out/soong/.intermediates/package-dir/module-name/gen/package-dir", + "out/soong/.intermediates/package-dir/module-name/gen", + "out/soong/.intermediates/package-dir/module-name/gen/package-dir/bar", + "out/soong/.intermediates/package-dir/module-name/gen/bar", + } + gen := result.Module("module-name", "").(*Module) + + android.AssertPathsRelativeToTopEquals( + t, + "include path", + exportedIncludeDirs, + gen.GeneratedHeaderDirs(), + ) + android.AssertPathsRelativeToTopEquals( + t, + "files", + []string{ + "out/soong/.intermediates/package-dir/module-name/gen/proto.h", + "out/soong/.intermediates/package-dir/module-name/gen/bar/proto.h", + }, + gen.GeneratedSourceFiles(), + ) +} + func TestGenSrcsWithNonRootAndroidBpOutputFiles(t *testing.T) { result := android.GroupFixturePreparers( prepareForGenRuleTest,