summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2019-06-13 00:28:16 +0200
committerPeter Scheibel <scheibel1@llnl.gov>2019-06-12 15:28:16 -0700
commit3ce90741a3dd82b22139f82a555e0158c796c169 (patch)
treef2693100b75cad8ec86a732092afacaf97887512
parentfe8297da74d9bcc1a3204a1019b949a80f7bfe40 (diff)
downloadspack-3ce90741a3dd82b22139f82a555e0158c796c169.tar.gz
spack-3ce90741a3dd82b22139f82a555e0158c796c169.tar.bz2
spack-3ce90741a3dd82b22139f82a555e0158c796c169.tar.xz
spack-3ce90741a3dd82b22139f82a555e0158c796c169.zip
Make "spack compiler find" check PATH by default (#11683)
Fixes #11678 `spack compiler find` was not searching `PATH` when provided with no arguments. ea7910a updated the API for the search function and the command logic did not update how it called this function. This also adds a test to ensure that `spack compiler find` will collect compilers from `PATH`.
-rw-r--r--lib/spack/spack/cmd/compiler.py3
-rw-r--r--lib/spack/spack/compilers/__init__.py2
-rw-r--r--lib/spack/spack/test/cmd/compiler_command.py33
-rw-r--r--lib/spack/spack/test/conftest.py28
-rw-r--r--lib/spack/spack/test/relocate.py15
5 files changed, 60 insertions, 21 deletions
diff --git a/lib/spack/spack/cmd/compiler.py b/lib/spack/spack/cmd/compiler.py
index 4c5078ba6b..5f7eaa7d45 100644
--- a/lib/spack/spack/cmd/compiler.py
+++ b/lib/spack/spack/cmd/compiler.py
@@ -73,7 +73,8 @@ def compiler_find(args):
add them to Spack's configuration.
"""
- paths = args.add_paths
+ # None signals spack.compiler.find_compilers to use its default logic
+ paths = args.add_paths or None
# Don't initialize compilers config via compilers.get_compiler_config.
# Just let compiler_find do the
diff --git a/lib/spack/spack/compilers/__init__.py b/lib/spack/spack/compilers/__init__.py
index bb0e431b5e..84f767d1dd 100644
--- a/lib/spack/spack/compilers/__init__.py
+++ b/lib/spack/spack/compilers/__init__.py
@@ -34,6 +34,8 @@ _other_instance_vars = ['modules', 'operating_system', 'environment',
'extra_rpaths']
_cache_config_file = []
+# TODO: Caches at module level make it difficult to mock configurations in
+# TODO: unit tests. It might be worth reworking their implementation.
#: cache of compilers constructed from config data, keyed by config entry id.
_compiler_cache = {}
diff --git a/lib/spack/spack/test/cmd/compiler_command.py b/lib/spack/spack/test/cmd/compiler_command.py
new file mode 100644
index 0000000000..042cb99484
--- /dev/null
+++ b/lib/spack/spack/test/cmd/compiler_command.py
@@ -0,0 +1,33 @@
+# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+import pytest
+
+import os
+import os.path
+
+import spack.main
+
+compiler = spack.main.SpackCommand('compiler')
+
+
+@pytest.fixture
+def no_compilers_yaml(mutable_config, monkeypatch):
+ """Creates a temporary configuration without compilers.yaml"""
+
+ for scope, local_config in mutable_config.scopes.items():
+ compilers_yaml = os.path.join(
+ local_config.path, scope, 'compilers.yaml'
+ )
+ if os.path.exists(compilers_yaml):
+ os.remove(compilers_yaml)
+
+
+@pytest.mark.regression('11678')
+@pytest.mark.requires_executables('/usr/bin/gcc')
+def test_compiler_find_without_paths(no_compilers_yaml):
+ output = compiler('find', '--scope=site')
+
+ assert 'gcc' in output
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
index 3ff1b1aaed..0b02d9fe93 100644
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -19,6 +19,7 @@ import ruamel.yaml as yaml
from llnl.util.filesystem import remove_linked_tree
import spack.architecture
+import spack.compilers
import spack.config
import spack.caches
import spack.database
@@ -202,6 +203,21 @@ def mock_fetch_cache(monkeypatch):
monkeypatch.setattr(spack.caches, 'fetch_cache', MockCache())
+@pytest.fixture(autouse=True)
+def _skip_if_missing_executables(request):
+ """Permits to mark tests with 'require_executables' and skip the
+ tests if the executables passed as arguments are not found.
+ """
+ if request.node.get_marker('requires_executables'):
+ required_execs = request.node.get_marker('requires_executables').args
+ missing_execs = [
+ x for x in required_execs if spack.util.executable.which(x) is None
+ ]
+ if missing_execs:
+ msg = 'could not find executables: {0}'
+ pytest.skip(msg.format(', '.join(missing_execs)))
+
+
# FIXME: The lines below should better be added to a fixture with
# FIXME: session-scope. Anyhow doing it is not easy, as it seems
# FIXME: there's some weird interaction with compilers during concretization.
@@ -306,22 +322,24 @@ def config(configuration_dir):
@pytest.fixture(scope='function')
-def mutable_config(tmpdir_factory, configuration_dir, config):
+def mutable_config(tmpdir_factory, configuration_dir, monkeypatch):
"""Like config, but tests can modify the configuration."""
spack.package_prefs.PackagePrefs.clear_caches()
mutable_dir = tmpdir_factory.mktemp('mutable_config').join('tmp')
configuration_dir.copy(mutable_dir)
- real_configuration = spack.config.config
-
- spack.config.config = spack.config.Configuration(
+ cfg = spack.config.Configuration(
*[spack.config.ConfigScope(name, str(mutable_dir))
for name in ['site', 'system', 'user']])
+ monkeypatch.setattr(spack.config, 'config', cfg)
+
+ # This is essential, otherwise the cache will create weird side effects
+ # that will compromise subsequent tests if compilers.yaml is modified
+ monkeypatch.setattr(spack.compilers, '_cache_config_file', [])
yield spack.config.config
- spack.config.config = real_configuration
spack.package_prefs.PackagePrefs.clear_caches()
diff --git a/lib/spack/spack/test/relocate.py b/lib/spack/spack/test/relocate.py
index 083686d5e6..f070e150c7 100644
--- a/lib/spack/spack/test/relocate.py
+++ b/lib/spack/spack/test/relocate.py
@@ -17,21 +17,6 @@ import spack.tengine
import spack.util.executable
-@pytest.fixture(autouse=True)
-def _skip_if_missing_executables(request):
- """Permits to mark tests with 'require_executables' and skip the
- tests if the executables passed as arguments are not found.
- """
- if request.node.get_marker('requires_executables'):
- required_execs = request.node.get_marker('requires_executables').args
- missings_execs = [
- x for x in required_execs if spack.util.executable.which(x) is None
- ]
- if missings_execs:
- msg = 'could not find executables: {0}'
- pytest.skip(msg.format(', '.join(missings_execs)))
-
-
@pytest.fixture(params=[True, False])
def is_relocatable(request):
return request.param