Respect $PATH ordering when registering compilers (#17967)

This commit is contained in:
Harmen Stoppels 2020-08-12 13:38:08 +02:00 committed by GitHub
parent 12aa6d221c
commit edcc334631
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 3 deletions

View file

@ -576,9 +576,7 @@ def _default(search_paths):
) )
command_arguments.append(detect_version_args) command_arguments.append(detect_version_args)
# Reverse it here so that the dict creation (last insert wins) return command_arguments
# does not spoil the intended precedence.
return reversed(command_arguments)
fn = getattr( fn = getattr(
operating_system, 'arguments_to_detect_version_fn', _default operating_system, 'arguments_to_detect_version_fn', _default

View file

@ -250,3 +250,35 @@ def test_compiler_find_prefer_no_suffix(
assert clang['paths']['cc'] == str(clangdir.join('clang')) assert clang['paths']['cc'] == str(clangdir.join('clang'))
assert clang['paths']['cxx'] == str(clangdir.join('clang++')) assert clang['paths']['cxx'] == str(clangdir.join('clang++'))
def test_compiler_find_path_order(
no_compilers_yaml, working_env, clangdir):
"""Ensure that we find compilers that come first in the PATH first
"""
with clangdir.as_cwd():
os.mkdir('first_in_path')
shutil.copy('gcc-8', 'first_in_path/gcc-8')
shutil.copy('g++-8', 'first_in_path/g++-8')
shutil.copy('gfortran-8', 'first_in_path/gfortran-8')
# the first_in_path folder should be searched first
os.environ['PATH'] = '{0}:{1}'.format(
str(clangdir.join("first_in_path")),
str(clangdir),
)
compiler('find', '--scope=site')
config = spack.compilers.get_compiler_config('site', False)
gcc = next(c['compiler'] for c in config
if c['compiler']['spec'] == 'gcc@8.4.0')
assert gcc['paths'] == {
'cc': str(clangdir.join('first_in_path', 'gcc-8')),
'cxx': str(clangdir.join('first_in_path', 'g++-8')),
'f77': str(clangdir.join('first_in_path', 'gfortran-8')),
'fc': str(clangdir.join('first_in_path', 'gfortran-8')),
}