Repository: spack/spack

Issue:
Installation issue: hwloc
On cori@NERSC and theta@ALCF, #7483 introduced a build regression.

    if '@2.0.0:' in self.spec:
        args.append('--enable-netloc')

netloc requires MPI, yet `hwloc` does not have an MPI dependency because it is commonly depended upon by MPI implementations (e.g., OpenMPI and at least one version of mpich- #15302).

Here is the debug log:

[tau.gcc@8.3.0.log](https://github.com/spack/spack/files/4423263/tau.gcc%408.3.0.log)

The relevant part is

	make[2]: Entering directory '/tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi'
		CC       netloc_rank_order.o
		CC       netloc_mpi_find_hosts-netloc_mpi_find_hosts.o
		CCLD     netloc_rank_order
		CCLD     netloc_mpi_find_hosts
	/usr/bin/ld: netloc_mpi_find_hosts-netloc_mpi_find_hosts.o: in function `main':
	/tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:40: undefined reference to `MPI_Init'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:42: undefined reference to `MPI_Comm_rank'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:43: undefined reference to `MPI_Comm_size'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:48: undefined reference to `MPI_Abort'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:57: undefined reference to `MPI_Get_processor_name'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:157: undefined reference to `MPI_Send'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:159: undefined reference to `MPI_Send'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:162: undefined reference to `MPI_Recv'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:223: undefined reference to `MPI_Finalize'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:93: undefined reference to `MPI_Recv'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:99: undefined reference to `MPI_Recv'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:116: undefined reference to `MPI_Send'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:112: undefined reference to `MPI_Send'
	/usr/bin/ld: /tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/utils/netloc/mpi/netloc_mpi_find_hosts.c:65: undefined reference to `MPI_Abort'
	collect2: error: ld returned 1 exit status

The detailed compilation logs:
[spack-cc-hwloc-naj47dq.in.log](https://github.com/spack/spack/files/4423287/spack-cc-hwloc-naj47dq.in.log)
[spack-cc-hwloc-naj47dq.out.log](https://github.com/spack/spack/files/4423288/spack-cc-hwloc-naj47dq.out.log)

Unsurprisingly, the compiler link directories don't include an MPI source:

	cc
	-g
	-O2
	-o
	.libs/netloc_mpi_find_hosts
	netloc_mpi_find_hosts-netloc_mpi_find_hosts.o
	../../../netloc/.libs/libnetloc.so
	-L/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/libpciaccess-0.13.5-3w47xhqx6yyf25w3xl6la7qmeswp2mx5/lib
	-L/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/libxml2-2.9.9-ys6suob3jslml7w6bfgovhytvicsiuey/lib
	-L/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/xz-5.2.5-v6hllz4ig7jsyb4wjkdtpaejcmuniv77/lib
	-L/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/zlib-1.2.11-opn2xungd3hfytvpnj5h6yt6bandexht/lib
	-L/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/libiconv-1.16-uwyfaltarblqnu3opnriickfqwku234g/lib
	/tmp/thaines/spack-stage/spack-stage-hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/spack-src/hwloc/.libs/libhwloc.so
	../../../hwloc/.libs/libhwloc.so
	/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/libpciaccess-0.13.5-3w47xhqx6yyf25w3xl6la7qmeswp2mx5/lib/libpciaccess.so
	/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/libxml2-2.9.9-ys6suob3jslml7w6bfgovhytvicsiuey/lib/libxml2.so
	-ldl
	-lz
	/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/xz-5.2.5-v6hllz4ig7jsyb4wjkdtpaejcmuniv77/lib/liblzma.so
	-lpthread
	/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/libiconv-1.16-uwyfaltarblqnu3opnriickfqwku234g/lib/libiconv.so
	-lm
	-pthread
	-Wl,-rpath
	-Wl,/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/hwloc-2.1.0-naj47dqjmbfpkol3dkjwrdtfz6xsv7qy/lib
	-Wl,-rpath
	-Wl,/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/libpciaccess-0.13.5-3w47xhqx6yyf25w3xl6la7qmeswp2mx5/lib
	-Wl,-rpath
	-Wl,/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/libxml2-2.9.9-ys6suob3jslml7w6bfgovhytvicsiuey/lib
	-Wl,-rpath
	-Wl,/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/xz-5.2.5-v6hllz4ig7jsyb4wjkdtpaejcmuniv77/lib
	-Wl,-rpath
	-Wl,/global/cscratch1/sd/thaines/spack/opt/spack/cray-cnl7-haswell/gcc-8.3.0/libiconv-1.16-uwyfaltarblqnu3opnriickfqwku234g/lib

I do not have an MPI module loaded

	$ module list
	Currently Loaded Modulefiles:
	1) modules/3.2.11.4                                 17) job/2.2.4-7.0.1.1_3.31__g36b56f4.ari
	2) nsg/1.2.0                                        18) dvs/2.12_2.2.151-7.0.1.1_5.33__g7eb5e703
	3) altd/2.0                                         19) alps/6.6.57-7.0.1.1_5.5__g1b735148.ari
	4) darshan/3.1.7                                    20) rca/2.2.20-7.0.1.1_4.37__g8e3fb5b.ari
	5) cray-mpich/7.7.10                                21) atp/2.1.3
	6) craype-haswell                                   22) PrgEnv-gnu/6.0.5
	7) craype-hugepages2M                               23) llvm/9.0.1
	8) craype-network-aries                             24) gcc/8.3.0
	9) craype/2.6.2                                     25) git/2.21.0
	10) cray-libsci/19.06.1                              26) cray-python/3.7.3.2
	11) udreg/2.3.2-7.0.1.1_3.26__g8175d3d.ari           27) boost-1.70.0-gcc-8.3.0-c7og6c2
	12) ugni/6.0.14.0-7.0.1.1_7.29__ge78e5b0.ari         28) cmake-3.16.5-gcc-8.3.0-rfdshcr
	13) pmi/5.0.14                                       29) elfutils-0.178-gcc-8.3.0-juylyy7
	14) dmapp/7.1.1-7.0.1.1_4.39__g38cf134.ari           30) intel-tbb-2020.1-gcc-8.3.0-wrxfw5i
	15) gni-headers/5.0.12.0-7.0.1.1_6.24__g3b1768f.ari  31) nano-4.4-gcc-8.3.0-kwiutcn
	16) xpmem/2.2.20-7.0.1.1_4.6__g0475745.ari           32) perl-5.30.1-gcc-8.3.0-d6sik3t


---
### Spack version
    $ spack --version
        0.14.1-411-5f308daf0

    $ git branch -v
        develop c3c057f2b package: update flit and py-pyelftools versions (#15817)

### Steps to reproduce the issue

    $ spack install hwloc@2.1.0%gcc@8.3.0~cairo~cuda~gl+libxml2~nvml+pci+shared

NB: This is the variant used by `tau` which is what I was actually installing.

### Platform and user environment

    $ uname -a
        Linux cori04 4.12.14-150.47-default #1 SMP Wed Dec 18 15:05:52 UTC 2019 (8162e25) x86_64 x86_64 x86_64 GNU/Linux

    $ lsb_release -d
        Description:	SUSE Linux Enterprise Server 15

### General information

- [x] I have run `spack --version` and reported the version of Spack
- [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/hwloc/package.py b/var/spack/repos/builtin/packages/hwloc/package.py
--- a/var/spack/repos/builtin/packages/hwloc/package.py
+++ b/var/spack/repos/builtin/packages/hwloc/package.py
@@ -57,6 +57,14 @@ class Hwloc(AutotoolsPackage):
         default=False,
         description='Enable the Cairo back-end of hwloc\'s lstopo command'
     )
+    variant(
+        'netloc',
+        default=False,
+        description="Enable netloc [requires MPI]"
+    )
+
+    # netloc isn't available until version 2.0.0
+    conflicts('+netloc', when="@:1.99.99")
 
     depends_on('pkgconfig', type='build')
     depends_on('m4', type='build', when='@master')
@@ -71,6 +79,10 @@ class Hwloc(AutotoolsPackage):
     depends_on('cairo', when='+cairo')
     depends_on('numactl', when='@:1.11.11 platform=linux')
 
+    # When mpi=openmpi, this introduces an unresolvable dependency.
+    # See https://github.com/spack/spack/issues/15836 for details
+    depends_on('mpi', when='+netloc')
+
     def url_for_version(self, version):
         return "http://www.open-mpi.org/software/hwloc/v%s/downloads/hwloc-%s.tar.gz" % (version.up_to(2), version)
 
@@ -81,7 +93,7 @@ def configure_args(self):
             # (Alternatively, we could require OpenCL as dependency.)
             "--disable-opencl",
         ]
-        if '@2.0.0:' in self.spec:
+        if '+netloc' in self.spec:
             args.append('--enable-netloc')
 
         args.extend(self.enable_or_disable('cairo'))


Test patch: