From 043b2cbb7c99d69a373f3ecbf35bc3b4638bcf85 Mon Sep 17 00:00:00 2001 From: Kyle Gerheiser <3209794+kgerheiser@users.noreply.github.com> Date: Fri, 17 Jun 2022 16:01:49 -0400 Subject: Fix external compiler detection for MPICH and OpenMPI (#30875) os.path.dirname was being used to compare compilers. If two compilers are in the same directory then it will pick up the first one it encounters. Compare the full compiler path instead. --- var/spack/repos/builtin/packages/mpich/package.py | 17 +++++++++-------- var/spack/repos/builtin/packages/openmpi/package.py | 12 ++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/var/spack/repos/builtin/packages/mpich/package.py b/var/spack/repos/builtin/packages/mpich/package.py index 2b8f9a435d..a66023734a 100644 --- a/var/spack/repos/builtin/packages/mpich/package.py +++ b/var/spack/repos/builtin/packages/mpich/package.py @@ -239,13 +239,13 @@ with '-Wl,-commons,use_dylibs' and without @classmethod def determine_variants(cls, exes, version): - def get_spack_compiler_spec(path): - spack_compilers = spack.compilers.find_compilers([path]) + def get_spack_compiler_spec(compiler): + spack_compilers = spack.compilers.find_compilers( + [os.path.dirname(compiler)]) actual_compiler = None # check if the compiler actually matches the one we want for spack_compiler in spack_compilers: - if (spack_compiler.cc and - os.path.dirname(spack_compiler.cc) == path): + if (spack_compiler.cc and spack_compiler.cc == compiler): actual_compiler = spack_compiler break return actual_compiler.spec if actual_compiler else None @@ -328,10 +328,11 @@ with '-Wl,-commons,use_dylibs' and without variants += '+hcoll' match = re.search(r'MPICH CC:\s+(\S+)', output) - compiler_spec = get_spack_compiler_spec( - os.path.dirname(match.group(1))) - if compiler_spec: - variants.append('%' + str(compiler_spec)) + if match: + compiler = match.group(1) + compiler_spec = get_spack_compiler_spec(compiler) + if compiler_spec: + variants.append('%' + str(compiler_spec)) results.append(' '.join(variants)) return results diff --git a/var/spack/repos/builtin/packages/openmpi/package.py b/var/spack/repos/builtin/packages/openmpi/package.py index 9274c951b8..7072581201 100644 --- a/var/spack/repos/builtin/packages/openmpi/package.py +++ b/var/spack/repos/builtin/packages/openmpi/package.py @@ -520,8 +520,8 @@ class Openmpi(AutotoolsPackage, CudaPackage): # Get the appropriate compiler match = re.search(r'\bC compiler absolute: (\S+)', output) if match: - compiler_spec = get_spack_compiler_spec( - os.path.dirname(match.group(1))) + compiler = match.group(1) + compiler_spec = get_spack_compiler_spec(compiler) if compiler_spec: variants.append("%" + str(compiler_spec)) results.append(' '.join(variants)) @@ -1053,13 +1053,13 @@ class Openmpi(AutotoolsPackage, CudaPackage): self._test_examples() -def get_spack_compiler_spec(path): - spack_compilers = spack.compilers.find_compilers([path]) +def get_spack_compiler_spec(compiler): + spack_compilers = spack.compilers.find_compilers( + [os.path.dirname(compiler)]) actual_compiler = None # check if the compiler actually matches the one we want for spack_compiler in spack_compilers: - if (spack_compiler.cc and - os.path.dirname(spack_compiler.cc) == path): + if (spack_compiler.cc and spack_compiler.cc == compiler): actual_compiler = spack_compiler break return actual_compiler.spec if actual_compiler else None -- cgit v1.2.3-70-g09d2