summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2020-08-12 13:38:08 +0200
committerGitHub <noreply@github.com>2020-08-12 13:38:08 +0200
commitedcc33463162995a1557122e34fa4a691077e980 (patch)
tree65db441f5ae14803b82937950f45eb04ec96f922 /lib
parent12aa6d221c945b75822f1d8ec69346fbd1a8d566 (diff)
downloadspack-edcc33463162995a1557122e34fa4a691077e980.tar.gz
spack-edcc33463162995a1557122e34fa4a691077e980.tar.bz2
spack-edcc33463162995a1557122e34fa4a691077e980.tar.xz
spack-edcc33463162995a1557122e34fa4a691077e980.zip
Respect $PATH ordering when registering compilers (#17967)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/compilers/__init__.py4
-rw-r--r--lib/spack/spack/test/cmd/compiler.py32
2 files changed, 33 insertions, 3 deletions
diff --git a/lib/spack/spack/compilers/__init__.py b/lib/spack/spack/compilers/__init__.py
index 36291a8f63..c11bafe47d 100644
--- a/lib/spack/spack/compilers/__init__.py
+++ b/lib/spack/spack/compilers/__init__.py
@@ -576,9 +576,7 @@ def arguments_to_detect_version_fn(operating_system, paths):
)
command_arguments.append(detect_version_args)
- # Reverse it here so that the dict creation (last insert wins)
- # does not spoil the intended precedence.
- return reversed(command_arguments)
+ return command_arguments
fn = getattr(
operating_system, 'arguments_to_detect_version_fn', _default
diff --git a/lib/spack/spack/test/cmd/compiler.py b/lib/spack/spack/test/cmd/compiler.py
index 61c67ccecd..c5c354221e 100644
--- a/lib/spack/spack/test/cmd/compiler.py
+++ b/lib/spack/spack/test/cmd/compiler.py
@@ -250,3 +250,35 @@ def test_compiler_find_prefer_no_suffix(
assert clang['paths']['cc'] == 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')),
+ }