Repository: spack/spack

Issue:
Installation issue: py-matplotlib
<!-- 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

spack install -j16 py-matplotlib

<!-- Fill in the exact spec you are trying to build and the relevant part of the error message -->
```console
$ spack install <spec>
...
/lib/spack/env/gcc/g++ -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -fPIC -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib__path_ARRAY_API -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -D__STDC_FORMAT_MACROS=1 -Iextern/agg24-svn/include -I/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/py-numpy-1.19.4-2bhftgmawvw5yfra4oofsryhn6zkmypo/lib/python3.7/site-packages/numpy/core/include -I/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/python-3.7.8-bjzum7plgrilh2k4xk35qu5fxchrvm5s/include/python3.7m -c extern/agg24-svn/src/agg_vcge
     630    /lib/spack/env/gcc/g++ -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -fPIC -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib__path_ARRAY_API -DNPY_NO_DEP
            RECATED_API=NPY_1_7_API_VERSION -D__STDC_FORMAT_MACROS=1 -Iextern/agg24-svn/include -I/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/py-numpy-1.19.4-2bhftgmawvw5yfra4oo
            RECATED_API=NPY_1_7_API_VERSION -D__STDC_FORMAT_MACROS=1 -Iextern/agg24-svn/include -I/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/py-numpy-1.19.4-2bhftgmawvw5yfra4oo
     632    /usr/lib64/distcc/g++ -pthread -shared build/temp.linux-x86_64-3.7/src/py_converters.o build/temp.linux-x86_64-3.7/src/_path_wrapper.o build/temp.linux-x86_64-3.7/exte
            rn/agg24-svn/src/agg_bezier_arc.o build/temp.linux-x86_64-3.7/extern/agg24-svn/src/agg_curves.o build/temp.linux-x86_64-3.7/extern/agg24-svn/src/agg_image_filters.o bu
            tator.o -L/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/python-3.7.8-bjzum7plgrilh2k4xk35qu5fxchrvm5s/lib -lpython3.7m -o build/lib.linux-x86_64-3.7/matplotlib/_path.c
            python-37m-x86_64-linux-gnu.so
     633    building 'matplotlib._qhull' extension
     634    /lib/spack/env/gcc/gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -fPIC -DMPL_DEVNULL=/dev/null -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib__qhu
            ll_ARRAY_API -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -D__STDC_FORMAT_MACROS=1 -I/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/py-numpy-1.19.4-2bhftgmawvw5yfra4oofs
            ryhn6zkmypo/lib/python3.7/site-packages/numpy/core/include -I/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/python-3.7.8-bjzum7plgrilh2k4xk35qu5fxchrvm5s/include/python
            3.7m -c src/qhull_wrap.c -o build/temp.linux-x86_64-3.7/src/qhull_wrap.o -fvisibility=hidden -flto
     635    /usr/lib64/distcc/gcc -pthread -shared -L/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/gettext-0.21-zezkketvjdhsptk2zvgjdltuizzppwst/lib -L/opt/spack/linux-mageia8-bro
            adwell/gcc-10.2.0/readline-8.0-2yrtmmu5ohqmexpwtujperhu4kc7grrj/lib -L/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/ncurses-6.2-jxmhn424fjw2jabjpwsthn33ft63zpxt/lib -L
            /opt/spack/linux-mageia8-broadwell/gcc-10.2.0/openssl-1.1.1h-7yhnwuqjvrn6u5l4q33orij6vlhxly6t/lib -L/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/sqlite-3.33.0-ybpx3ea
            2krr5j32vqbz7jdvonhhfa4gy/lib -L/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/gdbm-1.18.1-ngrlf3xgy7rfdmw4ej4mauosm3oksoc6/lib -L/opt/spack/linux-mageia8-broadwell/gcc
            -10.2.0/zlib-1.2.11-u2xnbctnh2v2k4rsho6pbkfilw4ztyvq/lib -L/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/bzip2-1.0.8-o5rfrqj5l2mjamylxp2scoq5x3qyytvr/lib -L/opt/spack/
            linux-mageia8-broadwell/gcc-10.2.0/xz-5.2.5-pfe3f3kb4mymzebz2g7gjql2xb3gb4ux/lib -L/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/expat-2.2.10-rnd6w7m4ik7i4rxzk7oytn442
            f5ewha6/lib -L/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/libffi-3.3-cqm5mpwjtyqkyrmpi6j3xaghbnfwgdxn/lib64 -L/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/libuuid-1
            .0.3-ijlg3p53xuxl2hbpb2vmwcwfaf7jgwvo/lib build/temp.linux-x86_64-3.7/src/qhull_wrap.o -L/opt/spack/linux-mageia8-broadwell/gcc-10.2.0/python-3.7.8-bjzum7plgrilh2k4xk3
            5qu5fxchrvm5s/lib -lqhull -lpython3.7m -o build/lib.linux-x86_64-3.7/matplotlib/_qhull.cpython-37m-x86_64-linux-gnu.so
  >> 636    /usr/bin/ld: cannot find -lqhull
  >> 637    collect2: error: ld returned 1 exit status
     638    distcc[30002] ERROR: compile (null) on localhost failed
  >> 639    error: command '/usr/lib64/distcc/gcc' failed with exit status 1

```

### Information on your system

* **Spack:** 0.15.4
* **Python:** 3.8.5
* **Platform:** linux-mageia8-skylake
<!-- 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. -->
* [spack-build-out.txt]()
* [spack-build-env.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. -->

@adamjstewart 

### 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
- [ ] 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:
Can you try again on the `develop` branch? I believe this was fixed by #17649.
tried it on the development branch but no joy.  The issue is not with the
compile but the link.

The odd thing is that the qhull library directory is not being added to the
link line, do you know where
spack knows where to link the qhull libs?

On Wed, Nov 11, 2020 at 12:47 AM Adam J. Stewart <notifications@github.com>
wrote:

> Can you try again on the develop branch? I believe this was fixed by
> #17649 <https://github.com/spack/spack/pull/17649>.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/spack/spack/issues/19843#issuecomment-724825670>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAWGAGMO4Z4FYFJCCLR22X3SPFVAXANCNFSM4TQR7S7A>
> .
>

Ah, I figured out the problem. Some parts of the build are using Spack's compiler wrapper (`/lib/spack/env/gcc/g++`). This automatically adds the appropriate linking flags for qhull. However, other parts of the build use the actual compiler (`/usr/lib64/distcc/gcc`), which doesn't know where to look for the `qhull` dependency. The solution is to add `qhull` and other dependencies to `LIBRARY_PATH`. Testing a fix now, I'll ping you when I open the PR. Thanks for the bug report!

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/py-matplotlib/package.py b/var/spack/repos/builtin/packages/py-matplotlib/package.py
--- a/var/spack/repos/builtin/packages/py-matplotlib/package.py
+++ b/var/spack/repos/builtin/packages/py-matplotlib/package.py
@@ -25,6 +25,7 @@ class PyMatplotlib(PythonPackage):
         'matplotlib.testing.jpl_units'
     ]
 
+    version('3.3.3', sha256='b1b60c6476c4cfe9e5cf8ab0d3127476fd3d5f05de0f343a452badaad0e4bdec')
     version('3.3.2', sha256='3d2edbf59367f03cd9daf42939ca06383a7d7803e3993eb5ff1bee8e8a3fbb6b')
     version('3.3.1', sha256='87f53bcce90772f942c2db56736788b39332d552461a5cb13f05ff45c1680f0e')
     version('3.3.0', sha256='24e8db94948019d531ce0bcd637ac24b1c8f6744ac86d2aa0eb6dbaeb1386f82')
@@ -86,7 +87,8 @@ class PyMatplotlib(PythonPackage):
     depends_on('freetype@2.3:')  # freetype 2.6.1 needed for tests to pass
     depends_on('qhull@2015.2:', when='@3.3:')
     depends_on('libpng@1.2:')
-    depends_on('py-certifi@2020.6.20:', when='@3.3.1:', type=('build', 'run'))
+    depends_on('py-certifi@2020.6.20:', when='@3.3.1:3.3.2', type=('build', 'run'))
+    depends_on('py-certifi@2020.6.20:', when='@3.3.3:', type='build')
     depends_on('py-numpy@1.11:', type=('build', 'run'))
     depends_on('py-numpy@1.15:', when='@3.3:', type=('build', 'run'))
     depends_on('py-setuptools', type=('build', 'run'))  # See #3813
@@ -149,6 +151,20 @@ class PyMatplotlib(PythonPackage):
     # Patch to pick up correct freetype headers
     patch('freetype-include-path.patch', when='@2.2.2:2.9.9')
 
+    def setup_build_environment(self, env):
+        include = []
+        library = []
+        for dep in self.spec.dependencies(deptype='link'):
+            query = self.spec[dep.name]
+            include.extend(query.headers.directories)
+            library.extend(query.libs.directories)
+
+        # Build uses a mix of Spack's compiler wrapper and the actual compiler,
+        # so this is needed to get parts of the build working.
+        # See https://github.com/spack/spack/issues/19843
+        env.set('CPATH', ':'.join(include))
+        env.set('LIBRARY_PATH', ':'.join(library))
+
     @run_before('build')
     def configure(self):
         """Set build options with regards to backend GUI libraries."""


Test patch: