summaryrefslogtreecommitdiff
path: root/lib
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 /lib
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 'lib')
-rw-r--r--lib/spack/spack/hooks/sbang.py4
-rw-r--r--lib/spack/spack/test/sbang.py18
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/spack/spack/hooks/sbang.py b/lib/spack/spack/hooks/sbang.py
index 324d5d4fbb..24d84db8af 100644
--- a/lib/spack/spack/hooks/sbang.py
+++ b/lib/spack/spack/hooks/sbang.py
@@ -64,6 +64,10 @@ def filter_shebang(path):
if re.search(r'^#!(/[^/\n]*)*lua\b', original):
original = re.sub(r'^#', '--', original)
+ # Use <?php #! instead of #! on second line for php.
+ if re.search(r'^#!(/[^/\n]*)*php\b', original):
+ original = re.sub(r'^#', '<?php #', original) + ' ?>'
+
# Use //! instead of #! on second line for node.js.
if re.search(r'^#!(/[^/\n]*)*node\b', original):
original = re.sub(r'^#', '//', original)
diff --git a/lib/spack/spack/test/sbang.py b/lib/spack/spack/test/sbang.py
index eeb68f20ab..c2d0adf4d2 100644
--- a/lib/spack/spack/test/sbang.py
+++ b/lib/spack/spack/test/sbang.py
@@ -30,6 +30,11 @@ node_line = "#!/this/" + ('x' * 200) + "/is/node\n"
node_in_text = ("line\n") * 100 + "lua\n" + ("line\n" * 100)
node_line_patched = "//!/this/" + ('x' * 200) + "/is/node\n"
sbang_line = '#!/bin/bash %s/bin/sbang\n' % spack.store.layout.root
+php_line = "#!/this/" + ('x' * 200) + "/is/php\n"
+php_in_text = ("line\n") * 100 + "php\n" + ("line\n" * 100)
+php_line_patched = "<?php #!/this/" + ('x' * 200) + "/is/php\n"
+php_line_patched2 = "?>\n"
+sbang_line = '#!/bin/bash %s/bin/sbang\n' % spack.store.layout.root
last_line = "last!\n"
@@ -79,6 +84,19 @@ class ScriptDirectory(object):
f.write(node_in_text)
f.write(last_line)
+ # php script with long shebang
+ self.php_shebang = os.path.join(self.tempdir, 'php')
+ with open(self.php_shebang, 'w') as f:
+ f.write(php_line)
+ f.write(last_line)
+
+ # php script with long shebang
+ self.php_textbang = os.path.join(self.tempdir, 'php_in_text')
+ with open(self.php_textbang, 'w') as f:
+ f.write(short_line)
+ f.write(php_in_text)
+ f.write(last_line)
+
# Script already using sbang.
self.has_sbang = os.path.join(self.tempdir, 'shebang')
with open(self.has_sbang, 'w') as f: