summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorToyohisa Kameyama <kameyama@riken.jp>2020-10-27 14:11:43 +0900
committerGitHub <noreply@github.com>2020-10-26 22:11:43 -0700
commitbb00b1a7c9eae3d307f0a22dcccae9e33a5885d0 (patch)
treee5c4a9e189bac786687ba3bdb0d17374923a3049 /bin
parentcb07d9ddb1e744c8e0f1aded64ab3f5bf9e5bae3 (diff)
downloadspack-bb00b1a7c9eae3d307f0a22dcccae9e33a5885d0.tar.gz
spack-bb00b1a7c9eae3d307f0a22dcccae9e33a5885d0.tar.bz2
spack-bb00b1a7c9eae3d307f0a22dcccae9e33a5885d0.tar.xz
spack-bb00b1a7c9eae3d307f0a22dcccae9e33a5885d0.zip
sbang: add support for php (#18299)
PHP supports an initial shebang, but its comment syntax can't handle our 2-line shebangs. So, we need to embed the 2nd-line shebang comment to look like a PHP comment: <?php #!/path/to/php ?> This adds patching support to the sbang hook and support for instrumenting php shebangs. This also patches `phar`, which is a tool used to create php packages. `phar` itself has to add sbangs to those packages (as phar archives apparently contain UTF-8, as well as binary blobs), and `phar` sets a checksum based on the contents of the package. Co-authored-by: Todd Gamblin <tgamblin@llnl.gov>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/sbang25
1 files changed, 18 insertions, 7 deletions
diff --git a/bin/sbang b/bin/sbang
index 5c9ad37acd..aba8658a7a 100755
--- a/bin/sbang
+++ b/bin/sbang
@@ -61,15 +61,23 @@
# Obviously, for this to work, `sbang` needs to have a short enough
# path that *it* will run without hitting OS limits.
#
-# For Lua, scripts the second line can't start with #!, as # is not
-# the comment character in lua (even though lua ignores #! on the
-# *first* line of a script). So, instrument a lua script like this,
-# using -- instead of # on the second line:
+# For Lua, node, and php scripts, the second line can't start with #!, as
+# # is not the comment character in these languages (though they all
+# ignore #! on the *first* line of a script). So, instrument such scripts
+# like this, using --, //, or <?php ... ?> instead of # on the second
+# line, e.g.:
#
# 1 #!/bin/bash /path/to/sbang
# 2 --!/long/path/to/lua with arguments
-# 3
-# 4 print "success!"
+# 3 print "success!"
+#
+# 1 #!/bin/bash /path/to/sbang
+# 2 //!/long/path/to/node with arguments
+# 3 print "success!"
+#
+# 1 #!/bin/bash /path/to/sbang
+# 2 <?php #/long/path/to/php with arguments ?>
+# 3 <?php echo "success!\n"; ?>
#
# How it works
# -----------------------------
@@ -90,6 +98,9 @@ while read line && ((lines < 2)) ; do
interpreter="${line#//!}"
elif [[ "$line" = '--!'*lua* ]]; then
interpreter="${line#--!}"
+ elif [[ "$line" = '<?php #!'*php* ]]; then
+ interpreter="${line#<?php\ \#!}"
+ interpreter="${interpreter%\ ?>}"
fi
lines=$((lines+1))
done < "$script"
@@ -98,7 +109,7 @@ done < "$script"
# #!/<spack-long-path>/perl -w
# this is the interpreter line with all the parameters as a vector
interpreter_v=(${interpreter})
-# this is the single interpreter path
+# this is the single interpreter path
interpreter_f="${interpreter_v[0]}"
# Invoke any interpreter found, or raise an error if none was found.