Closed brendanhay closed 3 years ago
Thanks for raising this and the detailed description.
This is a consequence of https://github.com/bazelbuild/bazel/issues/11736. //haskell:private/cc_libraries.bzl%haskell_cc_libraries_aspect
is used to obtain HaskellCcLibrariesInfo
and most other parts of rules_haskell depend on it. Unfortunately, aspect on aspect dependency cannot currently be expressed for aspects invoked from the command-line.
Makes sense - I'd seen the Bazel issue but the contributor responses aren't reassuring. Do you have any suggestions for how one might programmatically create a haskell_doc
target for hundreds of haskell_library
targets, instead? I'm currently running bazel query 'kind("haskell_library", //... -test/...)')
and the copy-pasta-ing the results into a haskell_doc
target which isn't ideal. I've seen various commentary around haskell_repl
's custom support for //...
wildcards in certain attributes - could haskell_doc
be extended in such a way or is this just too much of a hack? Writing a custom gazelle tool is also an option if I'm the only one encountering this.
Yes, BUILD file generation seems like a reasonable approach. A query is a simple way to obtain all library targets, on the generation side buildozer
could make it easy to create/update the haskell_doc
target in the BUILD file automatically. A custom Gazelle extension is of course also a possibility, though it may be overkill if all you want is a single haskell_doc
target for the entire repo.
The way haskell_repl
's wildcards work unfortunately doesn't solve the root issue here. Also haskell_repl
needs to be told about relevant targets in its deps
attribute. The wildcard mechanism is only about automatically including transitive dependencies of its deps
, but, it cannot discover all targets in the repo automatically by itself. Bazel simply doesn't allow this.
It didn't even occur to me to use buildozer. 🙄 Thanks!
For posterity:
# BUILD.bazel
haskell_doc(
name = "docs",
deps = []
)
bazel run --run_under "cd $PWD &&" @com_github_bazelbuild_buildtools//buildozer -- \
"set deps $(bazel query 'kind("haskell_library", //...)')" //:docs
(or, alternative title - ... doesn't appear to work as documented/understood)
The use case Generating API documentation section states:
Which I, perhaps naively, assume to mean I can generate the Haddock documentation of a
haskell_library
target without having to also define a corresponding (or top-level)haskell_doc
target for the library as follows:If I comment out the use of
HaskellCcLibrariesInfo
in haskell/haddock.bzl and replace it with an empty list, for testing:Everything appears to work -
HaskellCcLibrariesInfo
to allow use of the aspect in this way?bazel build //... --aspects @rules_haskell//haskell:defs.bzl%haskell_doc_aspect
?