Skip to content
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

Fixing Transitive Runfiles #26

Merged
merged 4 commits into from
Oct 28, 2023
Merged

Conversation

CauhxMilloy
Copy link
Contributor

Updating the call to ctx.runfiles() in the bats_test() impl function. Instead of setting transitive_files to the files of ctx.attr.data and ctx.attr.dep, this PR uses default_runfiles.files for deps. The effect is that all runfiles (not only the immediate outputs) of deps will be copied into the bats_test target's runfiles.

The existing issue can be shown when a bats_test() target's dep target contains data, it does not get copied over. Consider:

cc_binary(
  name = "tool",
  srcs = "main.cc",
  data = ["tool_config.txt"],
)
bats_test(
  name = "tool_test",
  deps = [":tool"],
)

In this example, the bats_test needs the :tool target (to run tests against the binary). With the current implementation, it will only get the binary. The data ("tool_config.txt") will not be copied over into the test runfiles. This is not only inconsistent (since running :tool would always have the file present), but it may (depending on the binary's functionality) cause the binary to no longer run correctly, as it depends on that file to be present. data files are also missing from any further transitive dependencies further in the build DAG.

This issue is also present with sh_binary for both data and deps, due to both attributes being treated as the same. This causes any transitive scripts (i.e. deps) to be missing in the bats_test runfiles.

This PR fixes this by gathering all runfiles (which includes deps and data + transitives) for each dep defined. This PR does not modify how data is processed, as data is moreso intended to explicitly list files (or filegroups) instead of targets (which would have their own deps/data). This distinction is merely a semantic one and data could also be processed in the same way in the future, if desired.

Your Name added 4 commits October 27, 2023 21:18
Updating the call to `ctx.runfiles()` in the `bats_test()` impl function.
Instead of setting `transitive_files` to the `files` of `ctx.attr.data` and `ctx.attr.dep`, this PR uses `default_runfiles.files` for `deps`.
The effect is that all runfiles (not only the immediate outputs) of `deps` will be copied into the `bats_test` target's runfiles.

The existing issue can be shown when a `bats_test()` target's `dep` target contains `data`, it does not get copied over.
Consider:
```python
cc_binary(
  name = "tool",
  srcs = "main.cc",
  data = ["tool_config.txt"],
)
bats_test(
  name = "tool_test",
  deps = [":tool"],
)
```

In this example, the `bats_test` needs the `:tool` target (to run tests against the binary).
With the current implementation, it will only get the binary.
The `data` (_"tool_config.txt"_) will not be copied over into the test runfiles.
This is not only inconsistent (since running `:tool` would always have the file present), but it may (depending on the binary's functionality) cause the binary to no longer run correctly, as it depends on that file to be present.
`data` files are also missing from any further transitive dependencies further in the build DAG.

This issue is also present with `sh_binary` for both `data` and `deps`, due to both attributes being treated as the same.
This causes any transitive scripts (i.e. `deps`) to be missing in the `bats_test` runfiles.

This PR fixes this by gathering all runfiles (which includes `deps` and `data` + transitives) for each dep defined.
This PR does not modify how `data` is processed, as `data` is moreso intended to explicitly list files (or `filegroups`) instead of targets (which would have their own `deps`/`data`).
This distinction is merely a semantic one and `data` could also be processed in the same way in the future, if desired.
@filmil filmil self-requested a review October 28, 2023 09:10
@filmil filmil merged commit 4aa002f into filmil:main Oct 28, 2023
@CauhxMilloy CauhxMilloy deleted the fixingTransitiveRunfiles branch March 4, 2024 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants