bazel-lib icon indicating copy to clipboard operation
bazel-lib copied to clipboard

`copy_to_directory` includes all files as runfiles

Open dieortin opened this issue 1 year ago • 3 comments

What happened?

When I use copy_to_directory in any step of my build, all copied files get included into archives generated with pkg_tar and include_runfiles=True. This makes it so, in addition to our binaries, we also get source files in the archive. This is because all files are added to the runfiles member of DefaultInfo: https://github.com/aspect-build/bazel-lib/blob/71a80525891942267bf1335d830652a0115dcfce/lib/private/copy_to_directory.bzl#L294C28-L294C36

Would it be possible to add an attribute to control whether files are added to runfiles or not?

Version

Development (host) and target OS/architectures: SUSE SLE RT 15 SP4

Output of bazel --version: bazel 6.5.0

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file: 1.37.0

Language(s) and/or frameworks involved:

How to reproduce

No response

Any other information?

No response

dieortin avatar Feb 06 '24 16:02 dieortin

I could imagine introducing a data attribute next to srcs, but it would be a breaking change to stop including the srcs in runfiles so I'm not sure that's feasible.

alexeagle avatar Feb 08 '24 20:02 alexeagle

That’s a good idea. Our current workaround is to have a custom rule that removes all runfiles from a target (we’re copying only C++ source files in our case)

dieortin avatar Feb 08 '24 20:02 dieortin

What about adding an attribute that does not add to runfiles? That would make the change non-breaking, although I’m not sure about naming

dieortin avatar Feb 08 '24 20:02 dieortin