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
cc-wrapper: fix bool handling for empty and zero values #35266
Conversation
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.
Great catch! I had verified a=''; let a |= <something>
works, but not when the RHS is empty. Just got these two code golf / style things.
@@ -25,7 +25,10 @@ mangleVarBool() { | |||
for infix in "${role_infixes[@]}"; do | |||
local inputVar="${var/+/${infix}}" | |||
if [ -v "$inputVar" ]; then | |||
let "${outputVar} |= ${!inputVar}" |
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 think one can directly do "${!inputVar:-0}"
?
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.
Ah, didn't know that!
local inputValue="${!inputVar}" | ||
# "1" in the end makes `let` return success error code when | ||
# expression itself evaluates to zero. | ||
let "${outputVar} |= ${inputValue:-0}" "1" |
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've just done || true
elsewhere, which I think is a bit easier to read
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.
The problem with || true
is that we cannot distinguish between a syntax error (inputValue="00ahaha"
) and legitimate zero.
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.
Oooo good point. Maybe add a comment about that too?
Before the code would fail silently for zero values and with some output for empties. We now currently handle both via defaulting value to zero and making `let` return success error code when there's no syntax error.
@Ericson2314 Updated with your suggestions, thanks! |
Motivation for this change
Before the code would fail silently for zero values and with some output for
empties. We now currently handle both via defaulting value to zero and making
let
return success error code when there's no syntax error.Test case:
nix-shell -A hello
export NIX_ENFORCE_NO_NATIVE=""
gcc --version
(observe error)export NIX_ENFORCE_NO_NATIVE=0
gcc --version
(observe silent failure)Things done
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)