Closed jondo2010 closed 5 years ago
That is not an option because the output depends on quite a few variables and it seems like too much effort to implement the analysis in Skylark.
I was not aware that .srcjar is not a general Bazel concept, but specific to Java. There might be an alternative that works across different languages though. I'll look into it.
@jondo2010 Unfortunately there currently is no uniform way to feed rules with output that is not known at analysis phase. Some rules support archives, but not C++ and it probably won't be added. But an alternative is coming and seems to be nearly ready (for C++ at least).
In the meantime I propose the following workaround that should support most use cases: specify the generated files in the BUILD
file. It's a bit cumbersome but as the filenames usually don't change often, it should be sufficient until Bazel has matured.
It would look like this:
antlr4(
name = "generated",
srcs = ["src/antlr4/Hello.g4"],
language = "Cpp",
output = [
"HelloParser.h",
"HelloLexer.tokens",
"HelloBaseListener.h",
"Hello.tokens",
"HelloParser.cpp",
"HelloLexer.cpp",
"HelloLexer.h",
"HelloLexer.interp",
"HelloListener.h",
"HelloBaseListener.cpp",
"Hello.interp",
"HelloListener.cpp"
],
)
To make things a bit easier, the rule could print the list of generated files that one can copy&paste in the BUILD
file. So initially you would specify some random output and invoke the antlr rule to gain the actual list for inclusion.
Does that sound viable?
Would be great to just generate the individual outputs into genfiles instead.