Generate genlex rules from bp2build for cc targets

This change will cause bp2build to generate genlex targets any
time a .l or .ll file is present in the srcs for a cc target and
add those genlex targets to the srcs attribute of the original
target.

Bug: 207408632
Test: unit tests
Change-Id: I1bce82c9d3c3d458eae1cef547ffae3d6e975134
This commit is contained in:
Trevor Radcliffe
2022-05-13 20:55:35 +00:00
parent 91f10eccc6
commit ef9c900ec3
8 changed files with 260 additions and 13 deletions

View File

@@ -2457,3 +2457,51 @@ func TestCcLibraryEscapeLdflags(t *testing.T) {
}),
})
}
func TestCcLibraryConvertLex(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
moduleTypeUnderTest: "cc_library",
moduleTypeUnderTestFactory: cc.LibraryFactory,
filesystem: map[string]string{
"foo.c": "",
"bar.cc": "",
"foo1.l": "",
"bar1.ll": "",
"foo2.l": "",
"bar2.ll": "",
},
blueprint: `cc_library {
name: "foo_lib",
srcs: ["foo.c", "bar.cc", "foo1.l", "foo2.l", "bar1.ll", "bar2.ll"],
lex: { flags: ["--foo_flags"] },
include_build_directory: false,
bazel_module: { bp2build_available: true },
}`,
expectedBazelTargets: append([]string{
makeBazelTarget("genlex", "foo_lib_genlex_l", attrNameToString{
"srcs": `[
"foo1.l",
"foo2.l",
]`,
"lexopts": `["--foo_flags"]`,
}),
makeBazelTarget("genlex", "foo_lib_genlex_ll", attrNameToString{
"srcs": `[
"bar1.ll",
"bar2.ll",
]`,
"lexopts": `["--foo_flags"]`,
}),
},
makeCcLibraryTargets("foo_lib", attrNameToString{
"srcs": `[
"bar.cc",
":foo_lib_genlex_ll",
]`,
"srcs_c": `[
"foo.c",
":foo_lib_genlex_l",
]`,
})...),
})
}