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

runnable_binary: avoid using > on the output file #1270

Merged
merged 2 commits into from
Sep 4, 2024

Conversation

novas0x2a
Copy link
Contributor

@novas0x2a novas0x2a commented Aug 24, 2024

In #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.

SH_BINARY_FILENAME also wasn't used, so this skips a step.

@novas0x2a novas0x2a force-pushed the runnable-copy branch 2 times, most recently from ab6934b to f8f5c1f Compare August 24, 2024 06:41
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.

SH_BINARY_FILENAME also wasn't used, so this skips a step.
@@ -44,7 +44,7 @@ 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 > $@
Copy link

Choose a reason for hiding this comment

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

note[nonblocking]: I was wondering about this, so I checked on the history. SH_BINARY_FILENAME was added in 41c937a and the last (and only) use was removed in 4831827, so it seems like a pretty safe clean up.

@jsharpe jsharpe enabled auto-merge (squash) September 4, 2024 18:23
@jsharpe jsharpe merged commit 1d8e362 into bazel-contrib:main Sep 4, 2024
2 checks passed
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.

3 participants