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

copy_file: Do not add non-executables to default_runfiles #326

Merged
merged 2 commits into from
May 16, 2022

Conversation

fmeum
Copy link
Contributor

@fmeum fmeum commented Oct 16, 2021

copy_file currently includes the copied file in its runfiles even if it is not executable, which makes every rule depending on it have the file as a runfile (e.g. a cc_library depending on a copied header file via the hdrs attribute).

In an ideal world, according to https://docs.bazel.build/versions/main/skylark/rules.html#runfiles-features-to-avoid, copy_file would not need to specify any runfiles in the DefaultInfo it returns - specifying files should suffice. However, due to the existence of rules with legacy behavior, this would break compatibility (actually, already with sh_test in skylib's unit tests).

As a compromise that preserves compatibility with legacy rules but nevertheless cleans up the runfiles tree of depending rules, use the data_runfiles attribute of DefaultInfo if the copied file is not executable.

(Note: I noticed the problem with legacy rules only after submitting #325, so please ignore that one).

@google-cla google-cla bot added the cla: yes label Oct 16, 2021
fmeum added a commit to fmeum/rules_jni that referenced this pull request Oct 16, 2021
Works around bazelbuild/bazel-skylib#326 by not
using copy_file for utils.h.
fmeum added a commit to fmeum/rules_jni that referenced this pull request Oct 16, 2021
Works around bazelbuild/bazel-skylib#326 by not
using copy_file for utils.h.
Copy link
Collaborator

@tetromino tetromino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, but shouldn't we make the same change to write_file too?

@fmeum
Copy link
Contributor Author

fmeum commented Apr 4, 2022

@tetromino I have learned more about runfiles in the meantime and now believe that this change is not net positive: The only reason that setting runfiles is necessary at all in this case is the legacy behavior of native rules caused by bazelbuild/bazel#15043. I now think that it would make more sense to wait for the fix to land and at some point drop the runfiles attribute entirely from these rules instead of using the deprecated data_runfiles as a band aid fix in the meantime. Please let me know if you think differently, I'm still not sure I have a full grasp on the idiomatic way of specifying runfiles.

@tetromino
Copy link
Collaborator

I'm neutral on this - but note that stable Bazel users won't see the fix to bazelbuild/bazel#15052 until Bazel 7.

copy_file and write_file currently include the created file in their
runfiles even if it is not executable, which makes every rule depending
on it have the file as a runfile (e.g. a `cc_library` depending on a
copied header file via the hdrs attribute).

In an ideal world, according to
https://docs.bazel.build/versions/main/skylark/rules.html#runfiles-features-to-avoid,
copy_file would not need to specify any runfiles in the `DefaultInfo` it
returns. However, due to the existence of rules with legacy behavior,
this would break compatibility (actually, already with `sh_test` in
skylib's unit tests), see
bazelbuild/bazel#15043.

As a compromise that preserves compatibility with legacy rules but
nevertheless cleans up the runfiles tree of depending rules, use the
`data_runfiles` attribute of `DefaultInfo` if the copied file is not
executable.
@fmeum
Copy link
Contributor Author

fmeum commented Apr 14, 2022

@tetromino Good point. I made the change also for write_file and added (hopefully) helpful comments in both places.

Copy link
Collaborator

@tetromino tetromino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tetromino tetromino merged commit a832b8d into bazelbuild:main May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants