From 2912cf3e17f8e4ea2389cb37bfd6bec744fc54d5 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 30 Oct 2018 23:00:43 -0700 Subject: compilers: update clang fortran compiler wrapper selection (#9678) Clang has support for using different fortran compilers with the Clang executable. Spack includes logic to select a compiler wrapper symlink which refers to the fortran executable (since some build systems depend on the name of the compiler, e.g. 'gfortran' or 'flang'). This selection was previously based on the architecture, and chose incorrectly in some situations (e.g. for clang/gfortran on Linux). This replaces architecture-based wrapper selection with a selection that is based on the name of the Fortran compiler executable. --- lib/spack/spack/compilers/clang.py | 60 ++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/lib/spack/spack/compilers/clang.py b/lib/spack/spack/compilers/clang.py index 7386ceb173..6f6f462559 100644 --- a/lib/spack/spack/compilers/clang.py +++ b/lib/spack/spack/compilers/clang.py @@ -16,6 +16,25 @@ from spack.util.executable import Executable from spack.version import ver +#: compiler symlink mappings for mixed f77 compilers +f77_mapping = [ + ('gfortran', 'clang/gfortran'), + ('xlf_r', 'xl_r/xlf_r'), + ('xlf', 'xl/xlf'), + ('pgfortran', 'pgi/pgfortran'), + ('ifort', 'intel/ifort') +] + +#: compiler symlink mappings for mixed f90/fc compilers +fc_mapping = [ + ('gfortran', 'clang/gfortran'), + ('xlf90_r', 'xl_r/xlf90_r'), + ('xlf90', 'xl/xlf90'), + ('pgfortran', 'pgi/pgfortran'), + ('ifort', 'intel/ifort') +] + + class Clang(Compiler): # Subclasses use possible names of C compiler cc_names = ['clang'] @@ -29,22 +48,31 @@ class Clang(Compiler): # Subclasses use possible names of Fortran 90 compiler fc_names = ['flang', 'gfortran', 'xlf90_r'] - # Named wrapper links within lib/spack/env - link_paths = {'cc': 'clang/clang', - 'cxx': 'clang/clang++'} - - if sys.platform == 'darwin': - # Use default wrappers for fortran, in case provided in - # compilers.yaml - link_paths['f77'] = 'clang/gfortran' - link_paths['fc'] = 'clang/gfortran' - elif spack.architecture.sys_type() == 'linux-rhel7-ppc64le': - # This platform uses clang with IBM XL Fortran compiler - link_paths['f77'] = 'xl_r/xlf_r' - link_paths['fc'] = 'xl_r/xlf90_r' - else: - link_paths['f77'] = 'clang/flang' - link_paths['fc'] = 'clang/flang' + # Clang has support for using different fortran compilers with the + # clang executable. + @property + def link_paths(self): + # clang links are always the same + link_paths = {'cc': 'clang/clang', + 'cxx': 'clang/clang++'} + + # fortran links need to look at the actual compiler names from + # compilers.yaml to figure out which named symlink to use + for compiler_name, link_path in f77_mapping: + if self.f77 and compiler_name in self.f77: + link_paths['f77'] = link_path + break + else: + link_paths['f77'] = 'clang/flang' + + for compiler_name, link_path in fc_mapping: + if self.fc and compiler_name in self.fc: + link_paths['fc'] = link_path + break + else: + link_paths['fc'] = 'clang/flang' + + return link_paths @property def is_apple(self): -- cgit v1.2.3-60-g2f50