bazel: Querying rdeps of BUILD file don't yield targets that BUILD file contains

We use an rdeps query to bazel to get a list of targets to rebuild based on a set of files that have changed. bazel query --keep_going 'kind(rule, rdeps(..., set(%s))) where %s is a set of files determined to have changed through some VCS query.

If that set only includes a bazel BUILD file, bazel’s rdeps query returns no targets, not even a genrule that’s in the BUILD file that changed.

Changed files: [u'realtime/BUILD'] Running builds and tests: []

This seems broken as the targets defined by a BUILD file should depend on that BUILD file, shouldn’t they?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 4
  • Comments: 30 (18 by maintainers)

Most upvoted comments

Hey @Globegitter , I’m sorry about the long silence. No, there haven’t been any updates.

IIUC, what @kavehv wanted to know was, if I change a file, what targets would be affected by it? And indeed this can be more than just the targets that explicitly reference this file in one of their attributes: for example the BUILD file affects all targets declared within it, and changing a header file in your system includes directory would have an effect on all cc_* rules and their rdeps.

From Bazel’s perspective, this translates to knowing the rdeps of an input file, not over the target graph but over the Skyframe graph. I believe in Skyframe that means rdeps of FileStateValues, with the results filtered for TargetValues.

There are numerous people far better qualified to comment on the viability of that than myself, so let me ping the first few people that come to mind: @janakdr, @michajlo, and @haxorz.

Then I believe the best way forward is to add some logic to the script invoking bazel to look at the delta since the last checkout, and if there are any BUILD files in there then run get the list of targets in that package (bazel query "kind(rule, //path/to/package:*)"), consider all of them invalid, plus take the rdeps of the rest of the changed files, and that’ll be the set of targets to rebuild.