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

cc-wrapper: fix bool handling for empty and zero values #35266

Merged
merged 1 commit into from Feb 21, 2018

Conversation

abbradar
Copy link
Member

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:

  1. nix-shell -A hello
  2. export NIX_ENFORCE_NO_NATIVE=""
  3. gcc --version (observe error)
  4. export NIX_ENFORCE_NO_NATIVE=0
  5. gcc --version (observe silent failure)
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Copy link
Member

@Ericson2314 Ericson2314 left a 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}"
Copy link
Member

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}"?

Copy link
Member Author

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"
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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.
@abbradar
Copy link
Member Author

@Ericson2314 Updated with your suggestions, thanks!

@Ericson2314 Ericson2314 merged commit e42e6d2 into NixOS:staging Feb 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants