diff options
author | Shea Levy <shea@shealevy.com> | 2018-04-09T14·54-0400 |
---|---|---|
committer | Shea Levy <shea@shealevy.com> | 2018-04-09T14·54-0400 |
commit | 7459388448278914662f796353279e84a49a5c99 (patch) | |
tree | 02157687950eefe6caa19922e9cb54b582563aef | |
parent | fd98fca7bbcea393957e63f25e36d82ada43e255 (diff) | |
parent | a4c9b2595e6e22250e4e744a35fff3c7f9cd85d9 (diff) |
Merge branch 'fix/ruby-shebang' of git://github.com/samueldr/nix
-rwxr-xr-x | src/nix-build/nix-build.cc | 2 | ||||
-rw-r--r-- | tests/nix-shell.sh | 9 | ||||
-rw-r--r-- | tests/shell.nix | 7 | ||||
-rw-r--r-- | tests/shell.shebang.rb | 7 |
4 files changed, 24 insertions, 1 deletions
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc index cf628519c6e7..a63b3e07ae77 100755 --- a/src/nix-build/nix-build.cc +++ b/src/nix-build/nix-build.cc @@ -212,7 +212,7 @@ void mainWrapped(int argc, char * * argv) // read the shebang to understand which packages to read from. Since // this is handled via nix-shell -p, we wrap our ruby script execution // in ruby -e 'load' which ignores the shebangs. - envCommand = (format("exec %1% %2% -e 'load(\"%3%\") -- %4%") % execArgs % interpreter % script % joined.str()).str(); + envCommand = (format("exec %1% %2% -e 'load(\"%3%\")' -- %4%") % execArgs % interpreter % script % joined.str()).str(); } else { envCommand = (format("exec %1% %2% %3% %4%") % execArgs % interpreter % script % joined.str()).str(); } diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh index 063e97ce2c75..d25c456cedfb 100644 --- a/tests/nix-shell.sh +++ b/tests/nix-shell.sh @@ -39,3 +39,12 @@ chmod a+rx $TEST_ROOT/shell.shebang.sh output=$($TEST_ROOT/shell.shebang.sh abc def) [ "$output" = "foo bar abc def" ] + +# Test nix-shell shebang mode for ruby +# This uses a fake interpreter that returns the arguments passed +# This, in turn, verifies the `rc` script is valid and the `load()` script (given using `-e`) is as expected. +sed -e "s|@SHELL_PROG@|$(type -p nix-shell)|" shell.shebang.rb > $TEST_ROOT/shell.shebang.rb +chmod a+rx $TEST_ROOT/shell.shebang.rb + +output=$($TEST_ROOT/shell.shebang.rb abc ruby) +[ "$output" = '-e load("'"$TEST_ROOT"'/shell.shebang.rb") -- abc ruby' ] diff --git a/tests/shell.nix b/tests/shell.nix index 5845d36fc161..eb39f9039a88 100644 --- a/tests/shell.nix +++ b/tests/shell.nix @@ -45,5 +45,12 @@ let pkgs = rec { bash = shell; + # ruby "interpreter" that outputs "$@" + ruby = runCommand "ruby" {} '' + mkdir -p $out/bin + echo 'printf -- "$*"' > $out/bin/ruby + chmod a+rx $out/bin/ruby + ''; + inherit pkgs; }; in pkgs diff --git a/tests/shell.shebang.rb b/tests/shell.shebang.rb new file mode 100644 index 000000000000..ea67eb09c1c6 --- /dev/null +++ b/tests/shell.shebang.rb @@ -0,0 +1,7 @@ +#! @SHELL_PROG@ +#! ruby +#! nix-shell -I nixpkgs=shell.nix --no-substitute +#! nix-shell --pure -p ruby -i ruby + +# Contents doesn't matter. +abort("This shouldn't be executed.") |