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`.
This commit is contained in:
Massimiliano Culpo 2019-06-13 00:28:16 +02:00 committed by Peter Scheibel
parent fe8297da74
commit 3ce90741a3
5 changed files with 60 additions and 21 deletions

View File

@ -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

View File

@ -34,6 +34,8 @@
'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 = {}

View File

@ -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

View File

@ -19,6 +19,7 @@
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 __str__(self):
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()

View File

@ -17,21 +17,6 @@
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