Skip to content

Commit

Permalink
don't set env vars for gfortran in minimal build environment, warn wh…
Browse files Browse the repository at this point in the history
…en gcc/g++ is not found, add logging
  • Loading branch information
boegel committed Aug 8, 2020
1 parent 58f9485 commit d464241
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
32 changes: 17 additions & 15 deletions easybuild/tools/toolchain/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@
import sys
import tempfile

from distutils.spawn import find_executable

from easybuild.base import fancylogger
from easybuild.tools.build_log import EasyBuildError, dry_run_msg
from easybuild.tools.build_log import EasyBuildError, dry_run_msg, print_warning
from easybuild.tools.config import build_option, install_path
from easybuild.tools.environment import setvar
from easybuild.tools.filetools import adjust_permissions, find_eb_script, read_file, which, write_file
Expand Down Expand Up @@ -245,21 +243,25 @@ def set_minimal_build_env(self):

# this is only relevant when using a system toolchain,
# for proper toolchains these variables will get set via the call to set_variables()
known_sys_compilers = {
'gcc': ['CC'],
'g++': ['CXX'],
'gfortran': ['F77', 'F90', 'FC'],
system_compilers = {
'gcc': 'CC',
'g++': 'CXX',
}

env_vars = {}
for compiler, flags in known_sys_compilers.items():
# distutils.spawn.find_executable() only returns first hit from $PATH
if find_executable(compiler):
for flag in flags:
env_vars.update({flag: compiler})

for name, value in env_vars.items():
setvar(name, value)
for cmd, env_var in system_compilers.items():
# which returns first hit from $PATH (or None if command was not found)
cmd_path = which(cmd)
if cmd_path:
self.log.info("Found compiler command %s at %s, so setting $%s in minimal build environment",
cmd, cmd_path, env_var)
env_vars.update({env_var: cmd})
else:
warning_msg = "%s command not found, not setting $%s in minimal build environment" % (cmd, env_var)
print_warning(warning_msg, log=self.log)

for key, value in env_vars.items():
setvar(key, value)

def base_init(self):
"""Initialise missing class attributes (log, options, variables)."""
Expand Down
7 changes: 4 additions & 3 deletions test/framework/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ def test_toolchain_compiler_env_vars(self):
tc.set_options({})
tc.prepare()

# only $CC and $CXX are set, no point is setting environment variables for Fortran
# since gfortran is often not installed on the system
self.assertEqual(os.getenv('CC'), 'gcc')
self.assertEqual(os.getenv('CXX'), 'g++')
self.assertEqual(os.getenv('F77'), 'gfortran')
self.assertEqual(os.getenv('F90'), 'gfortran')
self.assertEqual(os.getenv('FC'), 'gfortran')
for key in ['F77', 'F90', 'FC']:
self.assertEqual(os.getenv(key), None)

# env vars for compiler flags and MPI compiler commands are not set for system toolchain
flags_keys = ['CFLAGS', 'CXXFLAGS', 'F90FLAGS', 'FCFLAGS', 'FFLAGS']
Expand Down

0 comments on commit d464241

Please sign in to comment.