Skip to content

Commit

Permalink
runnable_binary: avoid using > on the output file
Browse files Browse the repository at this point in the history
In bazel-contrib#1267 there was an issue where, somehow, the wrapper script ended up as
a zero-length file but the action succeeded (resulting in storing a
zero-length file instead of the script in the caches). genrules are
documented as running inside `-ueo pipefail` so it seems like
this should be impossible...

In any case, this avoids using >$@ because the > runs before the command
itself does, creating a zero-length file before populating it, and is
the only way I could think of that this ends up as an empty file.
Hopefully, if the problem repeats, genrule will notice that the file
didn't get created and fail.
  • Loading branch information
novas0x2a committed Aug 24, 2024
1 parent d9367d2 commit a3cb4c5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion foreign_cc/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def runnable_binary(name, binary, foreign_cc_target, match_binary_name = False,

wrapper_cmd = """
sed s@EXECUTABLE@$(rlocationpath {name})@g $(location @rules_foreign_cc//foreign_cc/private:runnable_binary_wrapper.sh) > tmp
sed s@SH_BINARY_FILENAME@{sh_binary_filename}@g tmp > $@
sed s@SH_BINARY_FILENAME@{sh_binary_filename}@g tmp > tmp2
mv tmp2 $@
"""

if hasattr(native, "package_relative_label"):
Expand Down

0 comments on commit a3cb4c5

Please sign in to comment.