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

Quote paths in makeWrapper #23511

Merged
merged 1 commit into from Mar 16, 2017
Merged

Quote paths in makeWrapper #23511

merged 1 commit into from Mar 16, 2017

Conversation

abbradar
Copy link
Member

@abbradar abbradar commented Mar 5, 2017

Motivation for this change

Fixes #22962 (comment)

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
    • Linux
  • 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.

With this blink builds correctly. cc @rnhmjoj

@mention-bot
Copy link

@abbradar, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @Profpatsch and @vcunat to be potential reviewers.

local original=$1
local wrapper=$2
local original="$1"
local wrapper="$2"
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, someone pointed out to me once that these quotes:

local original="$1"

are unneeded. But I tend to add them anyway :-)

Copy link
Member Author

@abbradar abbradar Mar 5, 2017

Choose a reason for hiding this comment

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

I suspected so because it was unquoted in most places here, but:

[abbradar@abbradarbook:~]$ test() { local a=a b c; echo $a; }
[abbradar@abbradarbook:~]$ test
a
[abbradar@abbradarbook:~]$ test() { local a="a b c"; echo $a; }
[abbradar@abbradarbook:~]$ test
a b c

Copy link
Member Author

Choose a reason for hiding this comment

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

Eeeeeh, but:

[abbradar@abbradarbook:~]$ test() { local a=$1; echo $a; }
[abbradar@abbradarbook:~]$ test "a b c"
a b c

Bash is full of wonders...

Copy link
Contributor

Choose a reason for hiding this comment

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

Bash is full of wonders...

Indeed :-)

@rnhmjoj
Copy link
Contributor

rnhmjoj commented Mar 5, 2017

Thank you

@Profpatsch
Copy link
Member

Would it be possible to add some tests for cases that failed before and are now fixed?

mv $prog $hidden
makeWrapper $hidden $prog --argv0 '"$0"' "$@"
mv "$prog" "$hidden"
makeWrapper "$hidden" "$prog" --argv0 '$0' "$@"
Copy link
Member

Choose a reason for hiding this comment

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

Why remove the "" around $0 here? Doesn’t that change the expansion in some cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

$argv0 is already quoted now; see the line above (which you've also commented).

n=$((n + 1))
fi
done

# Note: extraFlagsArray is an array containing additional flags
# that may be set by --run actions.
echo exec ${argv0:+-a $argv0} "$original" \
$flagsBefore '"${extraFlagsArray[@]}"' '"$@"' >> $wrapper
echo exec ${argv0:+-a \"$argv0\"} \"$original\" \
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also add tests for non-trivial lines like these.

@abbradar
Copy link
Member Author

abbradar commented Mar 5, 2017

I'm not sure where nixpkgs tests are supposed to go but we definitely want to run tests for this, with as evil paths as possible :3

@Profpatsch
Copy link
Member

Sadly nowhere yet, but I might have something in the pipeline about that. ;)

@grahamc
Copy link
Member

grahamc commented Mar 6, 2017

you don't need evil test cases, use shellcheck :)

Can you run shellcheck against the script and see what it says?

@abbradar
Copy link
Member Author

abbradar commented Mar 7, 2017

@grahamc I feel ashamed always forgetting about this wonderful tool. Helped fix some more problems, thanks!

@rnhmjoj rnhmjoj mentioned this pull request Mar 15, 2017
50 tasks
@globin globin merged commit 7ff6eec into NixOS:staging Mar 16, 2017
vcunat pushed a commit that referenced this pull request Mar 19, 2017
Fixes #22962 (comment)

Also run ShellCheck.

(cherry picked from commit 7ff6eec)
For ZHF #23253 to fix e.g. blink.
@vcunat
Copy link
Member

vcunat commented Mar 20, 2017

The commit broke firewall test and consequently blocks nixos-unstable*. I've got no idea why ATM (bisected). They fail with:

starting VDE switch for network 1
running the VM test script
error: Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 1.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 4.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 5.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 9.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 16.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 17.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 20.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 24.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 1.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 4.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 5.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 9.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 16.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 17.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 20.
Global symbol "$walled" requires explicit package name (did you forget to declare "my $walled"?) at (eval 15) line 24.
vde_switch: EOF on stdin, cleaning up and exiting
cleaning up

@abbradar
Copy link
Member Author

abbradar commented Mar 20, 2017

There is some broken code in lib/testing.nix relying on old makeWrapper behaviour. I'm trying to fix that but stumbled into another Bashism:

$ foo=(a b c)
$ echo ${foo[@]}
a b c
$ echo "${foo[@]}"
$ # ??????

EDIT: no, this works (I can swear echo outputted nothing in the script but now it works -- maybe I typoed) -- something else is broken...

@abbradar
Copy link
Member Author

Ugh, so:

foo=(a b c)
wrapProgram --add-flags "${foo[@]}"

results in an empty argument list. My best guess is that becase wrapProgram is a Bash function, not a program, Bash passes arrays instead of strings and they break inside (because code is obviously not suited to handle arrays).

I made a workaround at abbradar@4b36413 which fixes this problem but haven't yet pushed it -- maybe some Bash guru knows how to do this more elegantly? (I argue that elegance is a relative concept so it can be applied even to Bash)

@abbradar
Copy link
Member Author

abbradar commented Mar 20, 2017

Oh, wait, I was just tricked by Bash again. "${foo[@]}" is interpreted as "expand an array into separate arguments" so my example above expands to wrapProgram a b c which breaks wrapProgram.

@abbradar
Copy link
Member Author

So the correct way to do what I wanted to is ${foo[*]}. Fix is pushed to master (1f0ce0e) and release.

@globin
Copy link
Member

globin commented Mar 27, 2017

This broke buildDotnetPackage see #24387

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

8 participants