Use `genrule` output directory as `srcs` for `ruby_library`
When using a genrule to generate ruby sources, it's helpful to output a directory and then use that for the sources of a ruby_library
For example:
genrule(
name = "gen-src-dir",
outs = ["some-directory"],
cmd = "mkdir -p $@ && touch $@/foo.rb $@/bar.rb"
)
ruby_library(
name = "my-lib",
srcs = [":gen-src-dir"],
)
Note that because these are generated files, it's hard to know what prefix to place in the include attribute, so ideally, that would allow itself to be relative to the output directory the genrule created.
Can you elaborate on why you'd want to use the output of a genrule as a ruby library? What's the use case here?
In the Selenium project, we generate support classes for handling the Chrome Debugging Protocol by transforming “pdl” files to ruby (and, indeed, other languages) Although we’ve not migrated the ruby build to bazel yet, our hand-rolled build system looks similar:
https://github.com/SeleniumHQ/selenium/blob/trunk/rb/build.desc#L336 is depended on by https://github.com/SeleniumHQ/selenium/blob/trunk/rb/build.desc#L291
In the more general case, this is useful for any time a code generator could be hooked into the build (think protobuf, APIs generated by OpenSwagger, parsers generated with Rangel, etc)
On 12 Nov 2020, at 21:01, Konstantin Gredeskoul [email protected] wrote:
Can you elaborate on why you'd want to use the output of a genrule as a ruby library? What's the use case here?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Is there any more information I could add to this to help explain the use case better?
I would ask this question on the Bazel/Ruby Slack channel: https://bazelbuild.slack.com/archives/CN4HMSK9Q
I wonder if you can generate a Ruby library from those files, and then use that as a dependency?
That's exactly what I'm trying to do :)