Repository: spack/spack

Issue:
build error in gnutls and cmake
I suspect the spack recipe for gnutls does not configure the guile
dependency correctly.  For me, a plain `spack install gnutls` from
today's checkout (88473a8da) fails in the config test for guile
(+guile is the default).

```
spack install -v gnutls
...
*** Detecting GNU Guile...

checking for guile-snarf... /home/krentel/gnutls/install/linux-fedora26-x86_64/gcc-7.3.1/guile-2.2.0-75otw6flosxdwhqg34ssilmgmxheaeae/bin/guile-snarf
checking for guild... /home/krentel/gnutls/install/linux-fedora26-x86_64/gcc-7.3.1/guile-2.2.0-75otw6flosxdwhqg34ssilmgmxheaeae/bin/guild
checking for pkg-config... (cached) /home/krentel/gnutls/install/linux-fedora26-x86_64/gcc-7.3.1/pkgconf-1.6.0-2hrubmn7tbszxx5ujal5nweramdldzsu/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
configure: checking for guile 2.2
configure: found guile 2.2
checking for guile-2.2... no
checking for guile2.2... no
checking for guile-2... no
checking for guile2... /usr/bin/guile2
configure: error: found development files for Guile 2.2, but /usr/bin/guile2 has effective version 2.0
==> Error: ProcessError: Command exited with status 1:
    '/home/krentel/gnutls/spack-repo/var/spack/stage/gnutls-3.6.8-kdysvilufknhd54qejpcbtnovfrrkaj4/gnutls-3.6.8/configure' '--prefix=/home/krentel/gnutls/install/linux-fedora26-x86_64/gcc-7.3.1/gnutls-3.6.8-kdysvilufknhd54qejpcbtnovfrrkaj4' '--enable-static' '--with-included-libtasn1' '--with-included-unistring' '--without-p11-kit' '--with-zlib' '--enable-guile' '--disable-tests' '--disable-valgrind-tests' '--disable-full-test-suite'

1 error found in build log:
     912    configure: checking for guile 2.2
     913    configure: found guile 2.2
     914    checking for guile-2.2... no
     915    checking for guile2.2... no
     916    checking for guile-2... no
     917    checking for guile2... /usr/bin/guile2
  >> 918    configure: error: found development files for Guile 2.2, but /usr/bin/guile2 has effective version 2.0
```

The spack recipe for gnutls already has:
```
depends_on('guile', when='+guile')
...
if '+guile' in spec:
    args.append('--enable-guile')
```

The error message suggests that gnutls configure needs some additional
args to find the spack-built guile over /usr/bin.

This also breaks the build for cmake because gnutls is now a
dependency for cmake.  (Which is where I saw this, I don't use gnutls
directly.)

A temporary workaround is `gnutls~guile`.

Investigations continue ....

### Steps to reproduce the issue

```
spack install gnutls
```

### Platform and user environment

x86_64, Linux Fedora 26, gcc 7.3.1, gnu glibc-2.25-13.fc26.x86_64

Packages.yaml is empty except for perl and python from /usr/bin.

```
packages:
  perl:
    paths:
      perl@5.24.4:  /usr
    buildable: False

  python:
    paths:
      python@2.7.15:  /usr
    buildable: False
```

### Additional information

The prereqs all built cleanly.
```
spack spec gnutls

gnutls@3.6.8%gcc@7.3.1+guile+zlib arch=linux-fedora26-x86_64
    ^gettext@0.19.8.1%gcc@7.3.1+bzip2+curses+git~libunistring+libxml2 patches=9acdb4e73f67c241b5ef32505c9ddf7cf6884ca8ea661692f21dca28483b04b8 +tar+xz arch=linux-fedora26-x86_64
        ^bzip2@1.0.6%gcc@7.3.1+shared arch=linux-fedora26-x86_64
            ^diffutils@3.7%gcc@7.3.1 arch=linux-fedora26-x86_64
        ^libxml2@2.9.9%gcc@7.3.1~python arch=linux-fedora26-x86_64
            ^libiconv@1.15%gcc@7.3.1 arch=linux-fedora26-x86_64
            ^pkgconf@1.6.0%gcc@7.3.1 arch=linux-fedora26-x86_64
            ^xz@5.2.4%gcc@7.3.1 arch=linux-fedora26-x86_64
            ^zlib@1.2.11%gcc@7.3.1+optimize+pic+shared arch=linux-fedora26-x86_64
        ^ncurses@6.1%gcc@7.3.1~symlinks~termlib arch=linux-fedora26-x86_64
        ^tar@1.31%gcc@7.3.1 arch=linux-fedora26-x86_64
    ^guile@2.2.0%gcc@7.3.1+readline+threads arch=linux-fedora26-x86_64
        ^bdw-gc@8.0.0%gcc@7.3.1+libatomic-ops arch=linux-fedora26-x86_64
            ^libatomic-ops@7.6.6%gcc@7.3.1 arch=linux-fedora26-x86_64
        ^gmp@6.1.2%gcc@7.3.1 arch=linux-fedora26-x86_64
            ^autoconf@2.69%gcc@7.3.1 arch=linux-fedora26-x86_64
                ^m4@1.4.18%gcc@7.3.1 patches=3877ab548f88597ab2327a2230ee048d2d07ace1062efe81fc92e91b7f39cd00,c0a408fbffb7255fcc75e26bd8edab116fc81d216bfd18b473668b7739a4158e,fc9b61654a3ba1a8d6cd78ce087e7c96366c290bc8d2c299f09828d793b853c8 +sigsegv arch=linux-fedora26-x86_64
                    ^libsigsegv@2.11%gcc@7.3.1 arch=linux-fedora26-x86_64
                ^perl@5.24.4%gcc@7.3.1+cpanm patches=0eac10ed90aeb0459ad8851f88081d439a4e41978e586ec743069e8b059370ac +shared+threads arch=linux-fedora26-x86_64
            ^automake@1.16.1%gcc@7.3.1 arch=linux-fedora26-x86_64
            ^libtool@2.4.6%gcc@7.3.1 arch=linux-fedora26-x86_64
        ^libffi@3.2.1%gcc@7.3.1 arch=linux-fedora26-x86_64
        ^libunistring@0.9.10%gcc@7.3.1 arch=linux-fedora26-x86_64
        ^readline@7.0%gcc@7.3.1 arch=linux-fedora26-x86_64
    ^nettle@3.4.1%gcc@7.3.1 arch=linux-fedora26-x86_64
```





Discussion:
This is more complicated than what I first thought.  Gnutls has config
vars `GUILE_CFLAGS` and `GUILE_LIBS` and I thought that would be
enough, but it appears not.

Gnutls config finds the spack-built pkg-config, finds the spack-built
guile 2.2.0, but then it looks for a versioned guile binary:
`guile-2.2`, `guile-2`, `guile2`, etc (see the above transcript).  The
spack-built guile doesn't provide this (only `guile`), so it falls
back on `/usr/bin/guile2` (2.0.14) which is a version mismatch.

It looks like `spack install gnutls +guile` (+guile is the default)
will fall over whenever the spec for guile differs from
/usr/bin/guile.  And even if they do match, it's an inconsistent build
that mixes two installs.

I don't see how to fix this without patching gnutls configure and
guile.m4, and that's a bit more than I want to dig into for a package
that I don't use.  (Currently, this also breaks cmake, which I do
use.)

ping @mathsen and @adamjstewart  who added +guile in #11571 a week ago.

I suggest resetting the default for guile to False until this gets
sorted out.


Resolving patch:
diff --git a/var/spack/repos/builtin/packages/gnutls/package.py b/var/spack/repos/builtin/packages/gnutls/package.py
--- a/var/spack/repos/builtin/packages/gnutls/package.py
+++ b/var/spack/repos/builtin/packages/gnutls/package.py
@@ -4,6 +4,7 @@
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
 from spack import *
+import os
 
 
 class Gnutls(AutotoolsPackage):
@@ -45,6 +46,12 @@ def url_for_version(self, version):
         url = "https://www.gnupg.org/ftp/gcrypt/gnutls/v{0}/gnutls-{1}.tar.xz"
         return url.format(version.up_to(2), version)
 
+    def setup_environment(self, build_env, run_env):
+        spec = self.spec
+        if '+guile' in spec:
+            build_env.set('GUILE', os.path.join(spec["guile"].prefix.bin,
+                                                'guile'))
+
     def configure_args(self):
         spec = self.spec
         args = [


Test patch: