Repository: spack/spack

Issue:
Installation issue: phist
It seems `phist` may need `sbang` patching for its build process, as it uses a python script configured by cmake (`fortran_bindings/cfwrapper.py.in`) where the python interpreter generated into the shebang lives in the spack install tree, which may be quite deep, depending on the installation root and any padding.  A recent `phist` build failed with the following error:

```
[ 23%] Generating phist_kernels.F90, phist_jada.F90, phist_tools.F90, phist_tools_s.F90, phist_tools_d.F90, phist_tools_c.F90, phist_tools_z.F90, phist_kernels_s.F90, phist_kernels_d.F90, phist_kernels_c.F90, phist_kernels_z.F90, phist_core_s.F90, phist_core_d.F90, phist_core_c.F90, phist_core_z.F90, phist_krylov_s.F90, phist_krylov_d.F90, phist_krylov_c.F90, phist_krylov_z.F90, phist_jada_s.F90, phist_jada_d.F90, phist_jada_c.F90, phist_jada_z.F90, phist_precon_s.F90, phist_precon_d.F90, phist_precon_c.F90, phist_precon_z.F90
cd /tmp/root/spack-stage/spack-stage-phist-1.9.3-qw6xyhd7kcq25y5a6pcsgozkrvdu3rwp/spack-build-qw6xyhd/fortran_bindings && ./cfwrapper.py
./cfwrapper.py: 39: ./cfwrapper.py:  Generates the *.F files from the C header files of phist.
    Command line:         python3 cfwrapper.py
    : not found
./cfwrapper.py: 41: ./cfwrapper.py: import: not found
./cfwrapper.py: 42: ./cfwrapper.py: import: not found
./cfwrapper.py: 43: ./cfwrapper.py: import: not found
./cfwrapper.py: 44: ./cfwrapper.py: import: not found
./cfwrapper.py: 45: ./cfwrapper.py: import: not found
./cfwrapper.py: 46: ./cfwrapper.py: import: not found
./cfwrapper.py: 47: ./cfwrapper.py: from: not found
./cfwrapper.py: 49: ./cfwrapper.py: from: not found
./cfwrapper.py: 51: ./cfwrapper.py: Syntax error: "(" unexpected
fortran_bindings/CMakeFiles/phist_fort.dir/build.make:109: recipe for target 'fortran_bindings/phist_kernels.F90' failed
make[2]: *** [fortran_bindings/phist_kernels.F90] Error 2
make[2]: Leaving directory '/tmp/root/spack-stage/spack-stage-phist-1.9.3-qw6xyhd7kcq25y5a6pcsgozkrvdu3rwp/spack-build-qw6xyhd'
CMakeFiles/Makefile2:3055: recipe for target 'fortran_bindings/CMakeFiles/phist_fort.dir/all' failed
make[1]: *** [fortran_bindings/CMakeFiles/phist_fort.dir/all] Error 2
make[1]: Leaving directory '/tmp/root/spack-stage/spack-stage-phist-1.9.3-qw6xyhd7kcq25y5a6pcsgozkrvdu3rwp/spack-build-qw6xyhd'
Makefile:184: recipe for target 'all' failed
make: *** [all] Error 2
```

Investigation showed that the shebang line generated into the `cfwrapper.py` file was longer than the max acceptable 127 characters, and when I simply added the `sbang` line before it, the problem went away.

### Information on your system

This occurred in a gitlab CI automated build of the `phist` package.  The attached spec.yaml file indicates the version, compiler, architecture, OS, etc, but to summarize, it was:

```
phist@1.9.3%gcc@7.5.0 arch=linux-ubuntu18.04-x86_64
```

This is happening with spack `develop` as of today ([c468d6bed2](https://github.com/spack/spack/commit/c468d6bed2f862e4221c0bd500f600bc29ab6092)).

### Additional information

Below is the spack build log:

[spack-build-out.txt](https://github.com/spack/spack/files/5587183/spack-build-out.txt)

Find attached below the spack environment:

[spack.yaml.txt](https://github.com/spack/spack/files/5587190/spack.yaml.txt)

This is the concrete phist spec serialized as yaml:

[phist.yaml.txt](https://github.com/spack/spack/files/5587191/phist.yaml.txt)



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/phist/package.py b/var/spack/repos/builtin/packages/phist/package.py
--- a/var/spack/repos/builtin/packages/phist/package.py
+++ b/var/spack/repos/builtin/packages/phist/package.py
@@ -5,6 +5,7 @@
 
 
 from spack import *
+import spack.hooks.sbang as sbang
 
 
 class Phist(CMakePackage):
@@ -101,6 +102,8 @@ class Phist(CMakePackage):
 
     patch('update_tpetra_gotypes.patch', when='@:1.8.99')
 
+    patch('sbang.patch', when='+fortran')
+
     # ###################### Dependencies ##########################
 
     depends_on('cmake@3.8:', type='build')
@@ -132,6 +135,9 @@ class Phist(CMakePackage):
     # to compile some OpenMP statements
     conflicts('%gcc@:4.9.1')
 
+    def setup_build_environment(self, env):
+        env.set('SPACK_SBANG', sbang.sbang_install_path())
+
     def cmake_args(self):
         spec = self.spec
 


Test patch: