Filtered watch for large directories #26688
canada-geek
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
Would applying |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
TL;DR: Add filters to
repository_ctx.watch_tree()
; only trigger repo refresh on changes to files matching pattern.We have a project for which we are prototyping a transition to using bazel. The primary build product is a set of device driver libraries.
The complication arises where the set of devices in the workspace can be fluid:
We are trying to set up our bazel rule set such that there are no hardcoded references to any specific devices; rather, we would like the bazel rules to remain device agnostic through a discovery mechanism.
For simplicity, let's say that the devices appear as directories with the pattern
<root>/driver/<device_name>
.Since per-device information is needed during the build, I have placed a
device_info.yaml
file in each device directory that contains information pertaining to that device.I've been able to achieve device discovery (and consumption of these info files) using a repository rule that scans for these files. The repository rule also sets up a
repository_ctx.watch()
for each such file in order to refresh the local repository when necessary.The complication comes when devices get added; there is no trigger to rerun the discovery and locate the newly added device(s).
The naive solution would be to use
repository_ctx.watch_tree()
on thedriver
subdirectory. However, given that this directory contains many hundreds of files (including the bulk of the source code), any change in source code would trigger a refresh of the repo unnecessarily.My proposal is to add filtering parameters to
watch_tree()
, such that only files matching this pattern (which could be a combination of include/exclude patterns similar toglob()
) would contribute to the watch.Note: I'm not an expert in this area; my assumption (please correct me if I've got this wrong) is that bazel is computing some sort of hash on the tree being watched, such that any content change (different hash) triggers a refresh of the repo. If this is the case, then a reduction of the set of files that contribute to the hash should not be a significant departure to the current implementation, while adding value for my use case.
I can probably create a patch for this, but before I make the attempt, I wanted to check in with you to discuss feasibility.
If you have alternate ways of achieving this, please help me learn more.
Thank you for your time and attention.
Beta Was this translation helpful? Give feedback.
All reactions