Repository: spack/spack

Issue:
Installation issue: petsc+trilinos (undefined symbols in libpytrilinos)
<!-- Thanks for taking the time to report this build failure. To proceed with the report please:

1. Title the issue "Installation issue: <name-of-the-package>".
2. Provide the information required below.

We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively! -->

### Steps to reproduce the issue

<!-- Fill in the exact spec you are trying to build and the relevant part of the error message -->
```console
$ spack install petsc +trilinos ^trilinos+python
```
fails to build with errors like
```console
TESTING: check from config.libraries(/tmp/spackswinst/spack-stage/spack-stage-petsc-3.13.1-uo3d3kxg6bobgcr5k2dfwnl3hccina3j/spack-src/config/BuildSystem/config/libraries.py:157)
*******************************************************************************
         UNABLE to CONFIGURE with GIVEN OPTIONS    (see configure.log for details):
-------------------------------------------------------------------------------
--with-trilinos-dir=/software/spack-software/2020.05.14/linux-rhel8-ivybridge/gcc-8.4.0/trilinos-13.0.0-ft22sgian7y355rzwkhj5w47g6tkh742 did not work
```
and the configure.log has errors like:
```console
Possible ERROR while running linker: exit code 1
stderr:
/software/spack-software/2020.05.14/linux-rhel8-ivybridge/gcc-8.4.0/trilinos-13.0.0-ft22sgian7y355rzwkhj5w47g6tkh742/lib/libpytrilinos.so: undefined reference to `PyType_IsSubtype'
/software/spack-software/2020.05.14/linux-rhel8-ivybridge/gcc-8.4.0/trilinos-13.0.0-ft22sgian7y355rzwkhj5w47g6tkh742/lib/libpytrilinos.so: undefined reference to `PyExc_RuntimeError'
/software/spack-software/2020.05.14/linux-rhel8-ivybridge/gcc-8.4.0/trilinos-13.0.0-ft22sgian7y355rzwkhj5w47g6tkh742/lib/libpytrilinos.so: undefined reference to `PyUnicode_FromString'
/software/spack-software/2020.05.14/linux-rhel8-ivybridge/gcc-8.4.0/trilinos-13.0.0-ft22sgian7y355rzwkhj5w47g6tkh742/lib/libpytrilinos.so: undefined reference to `PyErr_Print'
```

This appears to be related a known issue in Trilinos when one attempts to use the same build of Trilinos for both PyTrilinos and linking to C/C++ code (see e.g. 
https://github.com/trilinos/Trilinos/issues/569
or
https://github.com/trilinos/Trilinos/issues/866).  

Indeed the package.py for trilinos has a "hack" to remove PyTrilinos from the COMPONENTS_LIST in the cmake recipe, which is one of the remedial steps mentioned in the aforementioned URLs, but it neglects to "fix" the Makefile.export.Trilinos file.

Indeed, a quick test in which I manually editted the $prefix/include/Makefile.export.Trilinos to
remove the -lpytrilinos in the Trilinos_LIBRARIES make variable and then tried building petsc with the same parameters as above succeeded.

### Information on your system
```console
spack debug report
* **Spack:** 0.14.2
* **Python:** 3.6.8
* **Platform:** linux-rhel8-ivybridge
```

<!-- Please include the output of `spack debug report` -->

<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->

### Additional information

<!-- Please upload the following files. They should be present in the stage directory of the failing build. Also upload any config.log or similar file if one exists. -->
* [configure.log](https://github.com/spack/spack/files/5513855/configure.log)
* [spack-build-env.txt](https://github.com/spack/spack/files/5513856/spack-build-env.txt)
* [spack-build-out.txt](https://github.com/spack/spack/files/5513857/spack-build-out.txt)

<!-- Some packages have maintainers who have volunteered to debug build failures. Run `spack maintainers <name-of-the-package>` and @mention them here if they exist. -->

Petsc maintainers: @balay  @barrysmith  @jedbrown
Trilinos maintainers: @keitat

### General information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [ x] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [ x] I have run `spack maintainers <name-of-the-package>` and @mentioned any maintainers
- [ x] I have uploaded the build log and environment files
- [x ] I have searched the issues of this repo and believe this is not a duplicate



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/trilinos/package.py b/var/spack/repos/builtin/packages/trilinos/package.py
--- a/var/spack/repos/builtin/packages/trilinos/package.py
+++ b/var/spack/repos/builtin/packages/trilinos/package.py
@@ -731,13 +731,18 @@ def filter_python(self):
         # run-time error: Symbol not found: _PyBool_Type and prevents
         # Trilinos to be used in any C++ code, which links executable
         # against the libraries listed in Trilinos_LIBRARIES.  See
-        # https://github.com/Homebrew/homebrew-science/issues/2148#issuecomment-103614509
-        # A workaround is to remove PyTrilinos from the COMPONENTS_LIST :
+        # https://github.com/trilinos/Trilinos/issues/569 and
+        # https://github.com/trilinos/Trilinos/issues/866
+        # A workaround is to remove PyTrilinos from the COMPONENTS_LIST
+        # and to remove -lpytrilonos from Makefile.export.Trilinos
         if '+python' in self.spec:
             filter_file(r'(SET\(COMPONENTS_LIST.*)(PyTrilinos;)(.*)',
                         (r'\1\3'),
                         '%s/cmake/Trilinos/TrilinosConfig.cmake' %
                         self.prefix.lib)
+            filter_file(r'-lpytrilinos', '',
+                        '%s/Makefile.export.Trilinos' %
+                        self.prefix.include)
 
     def setup_run_environment(self, env):
         if '+exodus' in self.spec:


Test patch: