New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bazel rules for handling directories #494
Conversation
Build failures appear to be for an unrelated reason. |
It's not unrelated, the test runs on skylib itself and you thus need to add the new directory |
Ah, thanks, I was in a hurry when I looked at it last and didn't get a chance to fully check it out. Should be fixed now. |
The handling of this would be a lot simpler if this Bazel bug was fixed: Would it make sense to have a single
|
|
||
visibility("public") | ||
|
||
DirectoryInfo = provider( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This provider looks surprisingly heavyweight. Someone reaching for this kind of rule probably just wants to do something like:
ctx.actions.run(
executable = [ctx.executable._sphinx],
inputs = ctx.docs_root["DefaultInfo"].files.to_list(),
outputs = [out_dir],
arguments = [
ctx.docs_root["DirectoryInfo"].directory,
out_dir.path,
]
)
With the current provider's structure, how to achieve that goal is non-obvious to me. I understand that a lot of this information is handy (and in some cases critical to the current implementation), but it seems to get in the way of usability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, I created rules_directory to do this instead. I'll close this PR.
And I agree with your concerns, when rewriting for rules_directory I simplified it a lot. The following should now be possible:
directory(
name = "docs_root",
srcs = glob(["**/*"], exclude=["BUILD.bazel"])
)
foo_rule(
...,
docs_root = ":docs_root",
)
Then in the foo_rule implementation:
ctx.actions.run(
executable = [ctx.executable._sphinx],
inputs = ctx.docs_root[DefaultInfo].files.to_list(),
outputs = [out_dir],
arguments = [
# This is preferred. It auto-detects if it's a source directory or a generated directory and picks appropriately.
directory_path(ctx.docs_root[DirectoryInfo]),
# If it can't tell which it is, one of these may be required
ctx.docs_root[DirectoryInfo].source_path,
ctx.docs_root[DirectoryInfo].generated_path,
out_dir.path,
]
)
I first created this rule to better support sysroots inside rules_cc (bazelbuild/bazel#20334).
However, upon review, @t-rad679 wrote "This issue of wanting packages (directories) instead of individual target labels is coming up frequently for me. Maybe we could reuse this provider for use cases other than sysroot?".
I think this is sufficiently broadly applicable to work with anything. For example, here is some things I plan to do with it down the line:
@armandomontanez FYI
Note: for now, I haven't written any documentation, but I can add them once the concept gets approval.