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

stdenv-setup: Add quotes that don't do anything for consistency. #27614

Merged
merged 2 commits into from Jul 25, 2017

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Jul 24, 2017

Motivation for this change

@vcunat and others rightly point out that it's easier to quote always than learn Bash's idiosyncrasies enough to know when it doesn't make a difference.

This reverts commit 2743078, which removes quotes that don't do anything, and then goes further adding even more quotes.

Things done

Please check what applies. Note that these are not hard requirements but mereley serve as information for reviewers.

  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built stdenv on platform(s)
    • NixOS
    • macOS
    • Linux
  • 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.

if [ -d "$dir" ]; then
eval export ${varName}=${!varName}${!varName:+$delimiter}${dir}
export "${varName}=${!varName}${!varName:+$delimiter}${dir}"
Copy link
Member

Choose a reason for hiding this comment

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

OMG NONTRIVIAL CHANGE

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh. I had this branch sitting around for a while before my current tail-between-legs conservationism :D. But, spare me this one eval removal if stdenv builds :D:D?

local fd
local magic
exec {fd}< "$fn"
read -r -n 4 -u $fd magic
read -r -n 4 -u "$fd" magic
Copy link
Member

Choose a reason for hiding this comment

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

I don't even know what that exec {fd}< "$fn" means. Is fd guaranteed to have no spaces here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is.

Copy link
Member

Choose a reason for hiding this comment

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

It's a file descriptor, so yes. From the bash manpage:

Each redirection that may be preceded by a file descriptor number may instead be preceded by a word of the form {varname}. In this case, for each redirection operator except >&- and <&-, the shell will allocate a file descriptor greater than or equal to 10 and assign it to varname.

local fd
local magic
if ! [ -x /bin/sh ]; then return 0; fi
exec {fd}< "$fn"
read -r -n 2 -u $fd magic
read -r -n 2 -u "$fd" magic
Copy link
Member

Choose a reason for hiding this comment

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

Same question as above

Copy link
Member Author

Choose a reason for hiding this comment

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

Even before my general PR, my basic is philosophy with bash is

  • "$asdf" is a string substitution
  • "${asdf[@]}" is an array of strings substitution
  • $asdf is only for intentional re-splitting, and must be paired with a comment explaining why the re-splitting is happening.

This emulates a decent language where the first two have the same syntax, and the 3rd would be a combination of that syntax with some explicit coercion / splitting syntax.

In other words, don't forgo quoting because of a lack of deliminator in the definition. Even if that is obviously true it is still tempting fate, and per my bullets above is misleading because there is no intention of a word-splitting.

Copy link
Member

@copumpkin copumpkin left a comment

Choose a reason for hiding this comment

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

Looks pretty safe to me, but I'm not really a bash guru

The logic was made pure for the normal libSystem, but this change never
made it to the bootstrap tools. Deduplication the logic as the comment
suggests would have prevented this, but here's a stop-gap until we do
so.
@vcunat and others rightly point out that it's easier to quote always,
than learn Bash's idiosyncrasies enough to know when it doesn't make a
difference.

This reverts commit 2743078, which
removes quotes that don't do anything, and then goes further adding
even more quotes.
@Ericson2314
Copy link
Member Author

Built on both repos. I can now commence with the master -> staging merge :).

@Ericson2314 Ericson2314 merged commit 34c0ba4 into NixOS:staging Jul 25, 2017
@Ericson2314 Ericson2314 deleted the stdenv-quotes branch July 25, 2017 21:22
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.

None yet

3 participants