Merge branch 'fix/ruby-shebang' of git://github.com/samueldr/nix
This commit is contained in:
commit
7459388448
|
@ -212,7 +212,7 @@ void mainWrapped(int argc, char * * argv)
|
||||||
// read the shebang to understand which packages to read from. Since
|
// read the shebang to understand which packages to read from. Since
|
||||||
// this is handled via nix-shell -p, we wrap our ruby script execution
|
// this is handled via nix-shell -p, we wrap our ruby script execution
|
||||||
// in ruby -e 'load' which ignores the shebangs.
|
// 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 {
|
} else {
|
||||||
envCommand = (format("exec %1% %2% %3% %4%") % execArgs % interpreter % script % joined.str()).str();
|
envCommand = (format("exec %1% %2% %3% %4%") % execArgs % interpreter % script % joined.str()).str();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,3 +39,12 @@ chmod a+rx $TEST_ROOT/shell.shebang.sh
|
||||||
|
|
||||||
output=$($TEST_ROOT/shell.shebang.sh abc def)
|
output=$($TEST_ROOT/shell.shebang.sh abc def)
|
||||||
[ "$output" = "foo bar 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' ]
|
||||||
|
|
|
@ -45,5 +45,12 @@ let pkgs = rec {
|
||||||
|
|
||||||
bash = shell;
|
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;
|
inherit pkgs;
|
||||||
}; in pkgs
|
}; in pkgs
|
||||||
|
|
7
tests/shell.shebang.rb
Normal file
7
tests/shell.shebang.rb
Normal file
|
@ -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.")
|
Loading…
Reference in a new issue