Gen a header library when genrules export includes

Embedding multiple includes from a genrule may be difficult to read,
instead we generate a header library that contains the headers and all
include dirs that Soong generates.

Test: go test bp2build tests
Change-Id: I590c74c133f015f27cccf5a2fd916153ad9c125e
This commit is contained in:
Liz Kammer
2023-07-18 11:39:30 -04:00
parent 5f5dbaad65
commit 0db0e34c68
4 changed files with 175 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ package bp2build
import (
"fmt"
"path/filepath"
"testing"
"android/soong/android"
@@ -695,3 +696,79 @@ func TestCcGenruleArchAndExcludeSrcs(t *testing.T) {
})
})
}
func TestGenruleWithExportIncludeDirs(t *testing.T) {
testCases := []struct {
moduleType string
factory android.ModuleFactory
hod android.HostOrDeviceSupported
}{
{
moduleType: "genrule",
factory: genrule.GenRuleFactory,
},
{
moduleType: "cc_genrule",
factory: cc.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule",
factory: java.GenRuleFactory,
hod: android.DeviceSupported,
},
{
moduleType: "java_genrule_host",
factory: java.GenRuleFactoryHost,
hod: android.HostSupported,
},
}
dir := "baz"
bp := `%s {
name: "foo",
out: ["foo.out.h"],
srcs: ["foo.in"],
cmd: "cp $(in) $(out)",
export_include_dirs: ["foo", "bar", "."],
bazel_module: { bp2build_available: true },
}`
for _, tc := range testCases {
moduleAttrs := AttrNameToString{
"cmd": `"cp $(SRCS) $(OUTS)"`,
"outs": `["foo.out.h"]`,
"srcs": `["foo.in"]`,
}
expectedBazelTargets := []string{
makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
makeBazelTargetHostOrDevice("cc_library_headers", "foo__header_library", AttrNameToString{
"hdrs": `[":foo"]`,
"export_includes": `[
"foo",
"baz/foo",
"bar",
"baz/bar",
".",
"baz",
]`,
},
tc.hod),
}
t.Run(tc.moduleType, func(t *testing.T) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
Bp2buildTestCase{
ModuleTypeUnderTest: tc.moduleType,
ModuleTypeUnderTestFactory: tc.factory,
Filesystem: map[string]string{
filepath.Join(dir, "Android.bp"): fmt.Sprintf(bp, tc.moduleType),
},
Dir: dir,
ExpectedBazelTargets: expectedBazelTargets,
})
})
}
}