Repository: spack/spack

Issue:
Failed to build lammps
Lammps build failed with an error message "No spec with name lapack in lammps...".   I tried to specify `openblas` dependecy to it, but spec said "".

```
$ spack purge; spack clean lammps; spack install lammps %gcc@6 ^openmpi
==> Installing lammps
==> openmpi is externally installed in /lustre/spack/tools/linux-centos7-x86_64/gcc-6.
3.0/openmpi-2.0.2-wo3vh6hf2b64jhmlbvnapkaxlhkaxc2l
==> fftw is already installed in /lustre/spack/sandybridge/linux-centos7-x86_64/gcc-6.
3.0/fftw-3.3.6-pl1-bh5rh3gb7ab4swojghpvs6gn6pq45n2j
==> Using cached archive: /tmp/rpm/spack_source_cache/lammps/lammps-2016.11.17.tar.gz
==> Staging archive: /home/rpm/spack/var/spack/stage/lammps-2016.11.17-6s45pe4moej4nci
makgqx5qzh5juxzjj/stable_17Nov2016.tar.gz
==> Created stage in /home/rpm/spack/var/spack/stage/lammps-2016.11.17-6s45pe4moej4nci
makgqx5qzh5juxzjj
==> No patches needed for lammps
==> Building lammps [MakefilePackage]
==> Executing phase : 'edit'
==> Executing phase : 'build'
==> Error: KeyError: 'No spec with name lapack in lammps@2016.11.17%gcc@6.3.0+lib+manybody~meam~rigid~user-atc~user-nc-dump~voronoi arch=linux-centos7-x86_64 ^fftw@3.3.6-pl1%gcc@6.3.0+float+long_double+mpi+openmp~pfft_patches~quad arch=linux-centos7-x86_64 ^openmpi@2.0.2%gcc@6.3.0~java~mxm+pmi~psm~psm2+slurm~sqlite3~thread_multiple~tm+verbs+vt arch=linux-centos7-x86_64'
/home/rpm/spack/var/spack/repos/builtin/packages/lammps/package.py:169, in build_user_atc:
     145      def build_user_atc(self):
     146          with working_dir('lib/atc'):
     147              filter_file(r'CC =.*',
     148                          'CC = {0}'.format(self.compiler.cxx),
     149                          'Makefile.icc')
     150
     151              mpi_include = self.spec['mpi'].prefix.include
     152
     153              filter_file(r'CCFLAGS = *',
     154                          'CCFLAGS = -I{0} '.format(mpi_include),
     155                          'Makefile.icc')
     156
     157              filter_file('LINK =.*',
     158                          'LINK = {0}'.format(self.compiler.cxx),
     159                          'Makefile.icc')
     160
     161              make('lib', '-f', 'Makefile.icc')
     162              with open('Makefile.lammps', 'w') as fh:
     163                  lapack_blas = (self.spec['lapack'].libs +
     164                                 self.spec['blas'].libs)
     165                  makefile = [
     166                      'user-atc_SYSINC =',
     167                      'user-atc_SYSLIB = {0}'.format(lapack_blas.ld_flags),
     168                      'user-atc_SYSPATH = ']
  >> 169                  fh.write('\n'.join(makefile))

See build log for details:
  /tmp/rpm/spack_stage/spack-stage/spack-stage-hezeAV/lammps-stable_17Nov2016/spack-build.out

$ spack purge; spack clean lammps; spack install lammps %gcc@6 ^openmpi ^openblas
==> Error: lammps does not depend on openblas
```


Discussion:
strange, this code
```
lapack_blas = (self.spec['lapack'].libs +
                               self.spec['blas'].libs)
```
looks right to me. 

As for the spec, you need to do 
```
spack install lammps+user-atc %gcc@6 ^openmpi ^openblas
```
wait a second, the key to your issue is
```
Error: KeyError: 'No spec with name lapack in lammps@2016.11.17%gcc@6.3.0+lib+manybody~meam~rigid~user-atc~user-nc-dump~voronoi arch=linux-centos7-x86_64 ^fftw@3.3.6-pl1%gcc@6.3.0+float+long_double+mpi+openmp~pfft_patches~quad arch=linux-centos7-x86_64 ^openmpi@2.0.2%gcc@6.3.0~java~mxm+pmi~psm~psm2+slurm~sqlite3~thread_multiple~tm+verbs+vt arch=linux-centos7-x86_64'
```
namely you have `~user-atc`, thereby it **should NOT** get into `build_user_atc()` and query blas/lapack. So it's some bug in the package itself, not really related to Blas/Lapack.
@davydden you are right. Specifying `+user-atc` passes the blas checking.

```
spack install lammps+user-atc %gcc@6 ^openmpi ^openblas
```

But new a new issue arise. I'll check it and update my progress in this issue.

```
==> Using cached archive: /tmp/rpm/spack_source_cache/lammps/lammps-2016.11.17.tar.gz
==> Already staged lammps-2016.11.17-qnfnuwstesoe2hatoksp4mk76rxxpuvx in /home/rpm/spack/var/spack/stage/lammps-2016.11.17-qnfnuwstesoe2hatoksp4mk76rxxpuvx
==> No patches needed for lammps
==> Building lammps [MakefilePackage]
==> Executing phase : 'edit'
==> Executing phase : 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j32' 'gcc'
/home/rpm/spack/var/spack/repos/builtin/packages/lammps/package.py:194, in build:
     179      def build(self, spec, prefix):
     180          for pkg in self.supported_packages:
     181              _build_pkg_name = string.replace('build_{0}'.format(pkg), '-', '_')
     182              if hasattr(self, _build_pkg_name):
     183                  _build_pkg = getattr(self, _build_pkg_name)
     184                  _build_pkg()
     185
     186          with working_dir('src'):
     187              for pkg in self.supported_packages:
     188                  if '+{0}'.format(pkg) in spec:
     189                      make('yes-{0}'.format(pkg))
     190
     191              make(self.target_name)
     192
     193              if '+lib' in spec:
  >> 194                  make('mode=shlib', self.target_name)

$ tail /tmp/rpm/spack_stage/spack-stage/spack-stage-hRMn4A/lammps-stable_17Nov2016/spack-build.out

(many .o files) fix_temp_berendsen.o -latc  /lustre/spack/tools/linux-centos7-x86_64/gcc-6.3.0/openmpi-2.0.2-wo3vh6hf2b64jhmlbvnapkaxlhkaxc2l/lib/libmpi_cxx.so /lustre/spack/tools/linux-centos7-x86_64/gcc-6.3.0/openmpi-2.0.2-wo3vh6hf2b64jhmlbvnapkaxlhkaxc2l/lib/libmpi.so -lfftw3  -L/lustre/spack/sandybridge/linux-centos7-x86_64/gcc-6.3.0/openblas-0.2.19-rgo2z4hmxhte5oovdqmxj7ybnwj3yvbk/lib -lopenblas   -o ../lmp_gcc
../../lib/atc/libatc.a(LammpsInterface.o): In function `ATC::LammpsInterface::pair_eam() const':
/tmp/rpm/spack_stage/spack-stage/spack-stage-hRMn4A/lammps-stable_17Nov2016/lib/atc/LammpsInterface.cpp:1540: undefined reference to `typeinfo for LAMMPS_NS::PairEAM'
collect2: error: ld returned 1 exit status
make[1]: *** [../lmp_gcc] Error 1
make[1]: Leaving directory `/t
```

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/lammps/package.py b/var/spack/repos/builtin/packages/lammps/package.py
--- a/var/spack/repos/builtin/packages/lammps/package.py
+++ b/var/spack/repos/builtin/packages/lammps/package.py
@@ -24,7 +24,6 @@
 ##############################################################################
 from spack import *
 import os
-import string
 import datetime as dt
 
 
@@ -178,16 +177,16 @@ def build_voronoi(self):
 
     def build(self, spec, prefix):
         for pkg in self.supported_packages:
-            _build_pkg_name = string.replace('build_{0}'.format(pkg), '-', '_')
-            if hasattr(self, _build_pkg_name):
-                _build_pkg = getattr(self, _build_pkg_name)
-                _build_pkg()
+            if '+{0}'.format(pkg) in spec:
+                _build_pkg_name = 'build_{0}'.format(pkg.replace('-', '_'))
+                if hasattr(self, _build_pkg_name):
+                    _build_pkg = getattr(self, _build_pkg_name)
+                    _build_pkg()
 
-        with working_dir('src'):
-            for pkg in self.supported_packages:
-                if '+{0}'.format(pkg) in spec:
+                with working_dir('src'):
                     make('yes-{0}'.format(pkg))
 
+        with working_dir('src'):
             make(self.target_name)
 
             if '+lib' in spec:


Test patch: