Prefer later versions of compilers by default (#5234)

* Prefer later versions of compilers by default

* update test to make it less fragile
This commit is contained in:
scheibelp 2017-09-21 17:16:19 -07:00 committed by becker33
parent 3817111454
commit 45a8c03bdf
3 changed files with 18 additions and 24 deletions

View file

@ -317,6 +317,9 @@ def _proper_compiler_style(cspec, aspec):
# No compiler with a satisfactory spec was found # No compiler with a satisfactory spec was found
raise UnavailableCompilerVersionError(other_compiler) raise UnavailableCompilerVersionError(other_compiler)
# By default, prefer later versions of compilers
compiler_list = sorted(
compiler_list, key=lambda x: (x.name, x.version), reverse=True)
ppk = PackagePrefs(other_spec.name, 'compiler') ppk = PackagePrefs(other_spec.name, 'compiler')
matches = sorted(compiler_list, key=ppk) matches = sorted(compiler_list, key=ppk)

View file

@ -259,7 +259,10 @@ def _refresh():
with spack.store.db.write_transaction(): with spack.store.db.write_transaction():
for spec in spack.store.db.query(): for spec in spack.store.db.query():
t.uninstall(spec) if spec.package.installed:
t.uninstall(spec)
else:
spack.store.db.remove(spec)
install_path.remove(rec=1) install_path.remove(rec=1)
spack.store.root = str(spack_install_path) spack.store.root = str(spack_install_path)

View file

@ -25,6 +25,7 @@
import pytest import pytest
import shlex import shlex
import spack
import spack.spec as sp import spack.spec as sp
from spack.parse import Token from spack.parse import Token
from spack.spec import * from spack.spec import *
@ -314,33 +315,20 @@ def test_multiple_specs_with_hash(self, database):
assert len(specs) == 2 assert len(specs) == 2
def test_ambiguous_hash(self, database): def test_ambiguous_hash(self, database):
dbspecs = database.mock.db.query() x1 = Spec('a')
x1._hash = 'xy'
def find_ambiguous(specs, keyfun): x1._concrete = True
"""Return the first set of specs that's ambiguous under a x2 = Spec('a')
particular key function.""" x2._hash = 'xx'
key_to_spec = {} x2._concrete = True
for spec in specs: database.mock.db.add(x1, spack.store.layout)
key = keyfun(spec) database.mock.db.add(x2, spack.store.layout)
speclist = key_to_spec.setdefault(key, [])
speclist.append(spec)
if len(speclist) > 1:
return (key, speclist)
# If we fail here, we may need to guarantee that there are
# some ambiguos specs by adding more specs to the test DB
# until this succeeds.
raise RuntimeError("no ambiguous specs found for keyfun!")
# ambiguity in first hash character # ambiguity in first hash character
char, specs = find_ambiguous(dbspecs, lambda s: s.dag_hash()[0]) self._check_raises(AmbiguousHashError, ['/x'])
self._check_raises(AmbiguousHashError, ['/' + char])
# ambiguity in first hash character AND spec name # ambiguity in first hash character AND spec name
t, specs = find_ambiguous(dbspecs, self._check_raises(AmbiguousHashError, ['a/x'])
lambda s: (s.name, s.dag_hash()[0]))
name, char = t
self._check_raises(AmbiguousHashError, [name + '/' + char])
def test_invalid_hash(self, database): def test_invalid_hash(self, database):
mpileaks_zmpi = database.mock.db.query_one('mpileaks ^zmpi') mpileaks_zmpi = database.mock.db.query_one('mpileaks ^zmpi')