mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 06:42:28 +00:00
Merge remote-tracking branch 'matthewbauer/nix-shell-relative-shebang' into more-nix-shell
This commit is contained in:
commit
8838f5c746
8
doc/manual/rl-next/shebang-relative.md
Normal file
8
doc/manual/rl-next/shebang-relative.md
Normal file
@ -0,0 +1,8 @@
|
||||
synopsis: ensure nix-shell shebang uses relative path
|
||||
prs: #5088
|
||||
description: {
|
||||
|
||||
`nix-shell` shebangs use the script file's relative location to resolve relative paths to files passed as command line arguments, but expression arguments were still evaluated using the current working directory as a base path.
|
||||
The new behavior is that evalutations are performed relative to the script.
|
||||
|
||||
}
|
@ -334,8 +334,13 @@ static void main_nix_build(int argc, char * * argv)
|
||||
exprs = {state->parseStdin()};
|
||||
else
|
||||
for (auto i : remainingArgs) {
|
||||
auto baseDir = inShebang && !packages ? absPath(dirOf(script)) : i;
|
||||
|
||||
if (fromArgs)
|
||||
exprs.push_back(state->parseExprFromString(std::move(i), state->rootPath(".")));
|
||||
exprs.push_back(state->parseExprFromString(
|
||||
std::move(i),
|
||||
inShebang ? lookupFileArg(*state, baseDir) : state->rootPath(".")
|
||||
));
|
||||
else {
|
||||
auto absolute = i;
|
||||
try {
|
||||
|
@ -65,6 +65,16 @@ 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 with an alternate working directory
|
||||
sed -e "s|@ENV_PROG@|$(type -P env)|" shell.shebang.expr > $TEST_ROOT/shell.shebang.expr
|
||||
chmod a+rx $TEST_ROOT/shell.shebang.expr
|
||||
# Should fail due to expressions using relative path
|
||||
! $TEST_ROOT/shell.shebang.expr bar
|
||||
cp shell.nix config.nix $TEST_ROOT
|
||||
# Should succeed
|
||||
output=$($TEST_ROOT/shell.shebang.expr bar)
|
||||
[ "$output" = '-e load(ARGV.shift) -- '"$TEST_ROOT"'/shell.shebang.expr bar' ]
|
||||
|
||||
# Test nix-shell shebang mode again with metacharacters in the filename.
|
||||
# First word of filename is chosen to not match any file in the test root.
|
||||
sed -e "s|@ENV_PROG@|$(type -P env)|" shell.shebang.sh > $TEST_ROOT/spaced\ \\\'\"shell.shebang.sh
|
||||
|
Loading…
Reference in New Issue
Block a user