diff options
author | Toyohisa Kameyama <kameyama@riken.jp> | 2020-10-27 14:11:43 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-26 22:11:43 -0700 |
commit | bb00b1a7c9eae3d307f0a22dcccae9e33a5885d0 (patch) | |
tree | e5c4a9e189bac786687ba3bdb0d17374923a3049 /var | |
parent | cb07d9ddb1e744c8e0f1aded64ab3f5bf9e5bae3 (diff) | |
download | spack-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 'var')
-rw-r--r-- | var/spack/repos/builtin/packages/php/package.py | 23 | ||||
-rwxr-xr-x | var/spack/repos/builtin/packages/php/sbang.patch | 42 |
2 files changed, 65 insertions, 0 deletions
diff --git a/var/spack/repos/builtin/packages/php/package.py b/var/spack/repos/builtin/packages/php/package.py index 714bfb0e8f..d5da45eb94 100644 --- a/var/spack/repos/builtin/packages/php/package.py +++ b/var/spack/repos/builtin/packages/php/package.py @@ -5,6 +5,8 @@ from spack import * +import spack.hooks.sbang as sbang + class Php(AutotoolsPackage): """ @@ -36,6 +38,27 @@ class Php(AutotoolsPackage): depends_on('libxml2') depends_on('sqlite') + patch('sbang.patch') + + def patch(self): + """ + phar sbang is added before build phase. + Because phar is php script with binary data + (Not UTF-8 text file) And phar is embeded own sha1 checksum. + """ + shebang_limit = 127 + + if len(self.prefix.bin.php) + 2 <= shebang_limit: + return + + new_sbang_line = '#!/bin/bash %s' % sbang.sbang_install_path() + original_bang = '-b "$(PHP_PHARCMD_BANG)"' + makefile = join_path('ext', 'phar', 'Makefile.frag') + filter_file( + original_bang, + original_bang + ' -z "{0}"'.format(new_sbang_line), + makefile, string=True) + def autoreconf(self, spec, prefix): bash = which('bash') bash('./buildconf', '--force') diff --git a/var/spack/repos/builtin/packages/php/sbang.patch b/var/spack/repos/builtin/packages/php/sbang.patch new file mode 100755 index 0000000000..aca17c8ff3 --- /dev/null +++ b/var/spack/repos/builtin/packages/php/sbang.patch @@ -0,0 +1,42 @@ +--- spack-src/ext/phar/phar/pharcommand.inc.org 2019-12-18 01:35:53.000000000 +0900 ++++ spack-src/ext/phar/phar/pharcommand.inc 2020-08-20 12:26:16.207347572 +0900 +@@ -68,6 +68,12 @@ + 'inf' => '<bang> Hash-bang line to start the archive (e.g. #!/usr/bin/php). The hash ' + .' mark itself \'#!\' and the newline character are optional.' + ), ++ 'z' => array( ++ 'typ' => 'any', ++ 'val' => NULL, ++ 'inf' => '<bang> Hash-bang line to start the archive for spack. The hash ' ++ .' mark itself \'#!\' and the newline character are optional.' ++ ), + 'c' => array( + 'typ' => 'compalg', + 'val' => NULL, +@@ -455,7 +461,7 @@ + */ + static function cli_cmd_arg_pack() + { +- $args = self::phar_args('abcFhilpsxy', 'pharnew'); ++ $args = self::phar_args('azbcFhilpsxy', 'pharnew'); + + $args[''] = array( + 'typ' => 'any', +@@ -560,6 +566,7 @@ + } + + $alias = $this->args['a']['val']; ++ $spack_hb = $this->args['z']['val']; + $hashbang = $this->args['b']['val']; + $archive = $this->args['f']['val']; + $hash = $this->args['h']['val']; +@@ -571,6 +578,9 @@ + $invregex = $this->args['x']['val']; + $input = $this->args['']['val']; + ++ if (isset($spack_hb)) { ++ $hashbang = "$spack_hb\n<?php #!$hashbang ?>"; ++ } + $hash = self::phar_check_hash($hash, $privkey); + + $phar = new Phar($archive, 0, $alias); |