summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric <muffgaga@gmx.de>2016-09-22 09:43:47 +0200
committerTodd Gamblin <tgamblin@llnl.gov>2016-09-22 00:43:47 -0700
commit025b779a30476dd2b6ba9851e4ef1d57812b97c7 (patch)
tree524b5b079dcc878214e70290b95d95f786210b34
parent98f9dd266fe53444c77bcb6b810dda788c1fa558 (diff)
downloadspack-025b779a30476dd2b6ba9851e4ef1d57812b97c7.tar.gz
spack-025b779a30476dd2b6ba9851e4ef1d57812b97c7.tar.bz2
spack-025b779a30476dd2b6ba9851e4ef1d57812b97c7.tar.xz
spack-025b779a30476dd2b6ba9851e4ef1d57812b97c7.zip
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.
-rwxr-xr-xbin/sbang8
-rw-r--r--lib/spack/spack/hooks/sbang.py12
2 files changed, 13 insertions, 7 deletions
diff --git a/bin/sbang b/bin/sbang
index 1ea5f06592..e71074b330 100755
--- a/bin/sbang
+++ b/bin/sbang
@@ -111,8 +111,12 @@ while read line && ((lines < 2)) ; do
done < "$script"
# Invoke any interpreter found, or raise an error if none was found.
-if [ -n "$interpreter" ]; then
- exec $interpreter "$@"
+if [[ -n "$interpreter" ]]; then
+ if [[ "${interpreter##*/}" = "perl" ]]; then
+ exec $interpreter -x "$@"
+ else
+ exec $interpreter "$@"
+ fi
else
echo "error: sbang found no interpreter in $script"
exit 1
diff --git a/lib/spack/spack/hooks/sbang.py b/lib/spack/spack/hooks/sbang.py
index 02c1ce3816..6f9736a018 100644
--- a/lib/spack/spack/hooks/sbang.py
+++ b/lib/spack/spack/hooks/sbang.py
@@ -81,8 +81,10 @@ def filter_shebang(path):
tty.warn("Patched overlong shebang in %s" % path)
-def filter_shebangs_in_directory(directory):
- for file in os.listdir(directory):
+def filter_shebangs_in_directory(directory, filenames=None):
+ if filenames is None:
+ filenames = os.listdir(directory)
+ for file in filenames:
path = os.path.join(directory, file)
# only handle files
@@ -104,6 +106,6 @@ def post_install(pkg):
"""This hook edits scripts so that they call /bin/bash
$spack_prefix/bin/sbang instead of something longer than the
shebang limit."""
- if not os.path.isdir(pkg.prefix.bin):
- return
- filter_shebangs_in_directory(pkg.prefix.bin)
+
+ for directory, _, filenames in os.walk(pkg.prefix):
+ filter_shebangs_in_directory(directory, filenames)