-
Notifications
You must be signed in to change notification settings - Fork 180
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
fix: allow multiple copy_file in the same package #324
base: main
Are you sure you want to change the base?
Conversation
Previously this failed on windows, as we wrote colliding batch files
Ping @tetromino |
def copy_cmd(ctx, src, dst): | ||
# Most Windows binaries built with MSVC use a certain argument quoting | ||
# scheme. Bazel uses that scheme too to quote arguments. However, | ||
# cmd.exe uses different semantics, so Bazel's quoting is wrong here. | ||
# To fix that we write the command to a .bat file so no command line | ||
# quoting or escaping is required. | ||
bat = ctx.actions.declare_file(ctx.label.name + "-cmd.bat") | ||
# Put a hash of the file name into the name of the generated batch file to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: users of the public API wouldn't observe a problem because only one declare_file happens per copy_file
rule, and so ctx.label.name
is sufficient to disambiguate.
We hit this in a scenario where a rule uses this library code and creates multiple actions.
def copy_cmd(ctx, src, dst): | ||
# Most Windows binaries built with MSVC use a certain argument quoting | ||
# scheme. Bazel uses that scheme too to quote arguments. However, | ||
# cmd.exe uses different semantics, so Bazel's quoting is wrong here. | ||
# To fix that we write the command to a .bat file so no command line | ||
# quoting or escaping is required. | ||
bat = ctx.actions.declare_file(ctx.label.name + "-cmd.bat") | ||
# Put a hash of the file name into the name of the generated batch file to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: users of the public API wouldn't observe a problem because only one declare_file happens per copy_file
rule, and so ctx.label.name
is sufficient to disambiguate.
We hit this in a scenario where a rule uses this library code and creates multiple actions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be blind here, but I don't think I understand the purpose of this change.
As far as I can see, two copy_file
targets (even with the same src) in the same package shouldn't collide on Windows because they will have different labels.
It seems the fix is only for a hypothetical situation where another rule's implementation in Skylib might call copy_cmd in a loop - but no such rule exists at the moment (again, as far as I can see).
Is this a prerequisite for another PR - if so, which one? I don't think that #323 should need this...
Yes I mentioned it in #324 (comment) Granted, that rule uses the private API of |
I'm wondering if we should instead bite the bullet and fix Wrote up my thoughts in bazelbuild/bazel#15194 |
That looks interesting, but it's totally orthogonal to this fix, right? |
If
|
Previously this failed on windows, as we wrote colliding batch files