Workaround to support ruby as an interpreter
This commit is contained in:
parent
0423787086
commit
2989783f64
1 changed files with 20 additions and 6 deletions
|
@ -191,18 +191,32 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
|
||||||
$n++;
|
$n++;
|
||||||
die "$0: ‘$arg’ requires an argument\n" unless $n < scalar @ARGV;
|
die "$0: ‘$arg’ requires an argument\n" unless $n < scalar @ARGV;
|
||||||
my $interpreter = $ARGV[$n];
|
my $interpreter = $ARGV[$n];
|
||||||
# Überhack to support Perl. Perl examines the shebang and
|
my $execArgs = "";
|
||||||
# executes it unless it contains the string "perl" or "indir",
|
|
||||||
# or (undocumented) argv[0] does not contain "perl". Exploit
|
|
||||||
# the latter by doing "exec -a".
|
|
||||||
my $execArgs = $interpreter =~ /perl/ ? "-a PERL" : "";
|
|
||||||
sub shellEscape {
|
sub shellEscape {
|
||||||
my $s = $_;
|
my $s = $_;
|
||||||
$s =~ s/'/'\\''/g;
|
$s =~ s/'/'\\''/g;
|
||||||
return "'" . $s . "'";
|
return "'" . $s . "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Überhack to support Perl. Perl examines the shebang and
|
||||||
|
# executes it unless it contains the string "perl" or "indir",
|
||||||
|
# or (undocumented) argv[0] does not contain "perl". Exploit
|
||||||
|
# the latter by doing "exec -a".
|
||||||
|
if ($interpreter =~ /perl/) {
|
||||||
|
$execArgs = "-a PERL";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($interpreter =~ /ruby/) {
|
||||||
|
# Hack for Ruby. Ruby also examines the shebang. It tries to
|
||||||
|
# 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 = "exec $execArgs $interpreter -e 'load(\"$script\")' -- ${\(join ' ', (map shellEscape, @savedArgs))}";
|
||||||
|
} else {
|
||||||
$envCommand = "exec $execArgs $interpreter $script ${\(join ' ', (map shellEscape, @savedArgs))}";
|
$envCommand = "exec $execArgs $interpreter $script ${\(join ' ', (map shellEscape, @savedArgs))}";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
elsif (substr($arg, 0, 1) eq "-") {
|
elsif (substr($arg, 0, 1) eq "-") {
|
||||||
push @buildArgs, $arg;
|
push @buildArgs, $arg;
|
||||||
|
|
Loading…
Reference in a new issue