Fix sbang for perl (#1802)
* Perform shebang fix for all files * Fix sbang for perl scripts Otherwise perl would look at the #! line and call sbang again, resulting in an infinite loop.
This commit is contained in:
parent
98f9dd266f
commit
025b779a30
2 changed files with 13 additions and 7 deletions
|
@ -111,8 +111,12 @@ while read line && ((lines < 2)) ; do
|
||||||
done < "$script"
|
done < "$script"
|
||||||
|
|
||||||
# Invoke any interpreter found, or raise an error if none was found.
|
# Invoke any interpreter found, or raise an error if none was found.
|
||||||
if [ -n "$interpreter" ]; then
|
if [[ -n "$interpreter" ]]; then
|
||||||
exec $interpreter "$@"
|
if [[ "${interpreter##*/}" = "perl" ]]; then
|
||||||
|
exec $interpreter -x "$@"
|
||||||
|
else
|
||||||
|
exec $interpreter "$@"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "error: sbang found no interpreter in $script"
|
echo "error: sbang found no interpreter in $script"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -81,8 +81,10 @@ def filter_shebang(path):
|
||||||
tty.warn("Patched overlong shebang in %s" % path)
|
tty.warn("Patched overlong shebang in %s" % path)
|
||||||
|
|
||||||
|
|
||||||
def filter_shebangs_in_directory(directory):
|
def filter_shebangs_in_directory(directory, filenames=None):
|
||||||
for file in os.listdir(directory):
|
if filenames is None:
|
||||||
|
filenames = os.listdir(directory)
|
||||||
|
for file in filenames:
|
||||||
path = os.path.join(directory, file)
|
path = os.path.join(directory, file)
|
||||||
|
|
||||||
# only handle files
|
# only handle files
|
||||||
|
@ -104,6 +106,6 @@ def post_install(pkg):
|
||||||
"""This hook edits scripts so that they call /bin/bash
|
"""This hook edits scripts so that they call /bin/bash
|
||||||
$spack_prefix/bin/sbang instead of something longer than the
|
$spack_prefix/bin/sbang instead of something longer than the
|
||||||
shebang limit."""
|
shebang limit."""
|
||||||
if not os.path.isdir(pkg.prefix.bin):
|
|
||||||
return
|
for directory, _, filenames in os.walk(pkg.prefix):
|
||||||
filter_shebangs_in_directory(pkg.prefix.bin)
|
filter_shebangs_in_directory(directory, filenames)
|
||||||
|
|
Loading…
Reference in a new issue