Extracted a function transforming path hints to search paths
Given a list of possible paths it returns a list of the existing real paths and of their 'bin' subdirectories, if they exist.
This commit is contained in:
parent
06cc799fd3
commit
0a8f4ad42e
@ -58,6 +58,7 @@
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import inspect
|
import inspect
|
||||||
|
import itertools
|
||||||
import platform as py_platform
|
import platform as py_platform
|
||||||
|
|
||||||
import llnl.util.multiproc as mp
|
import llnl.util.multiproc as mp
|
||||||
@ -231,28 +232,13 @@ def __repr__(self):
|
|||||||
def _cmp_key(self):
|
def _cmp_key(self):
|
||||||
return (self.name, self.version)
|
return (self.name, self.version)
|
||||||
|
|
||||||
def find_compilers(self, *paths):
|
def find_compilers(self, *path_hints):
|
||||||
"""
|
"""
|
||||||
Return a list of compilers found in the supplied paths.
|
Return a list of compilers found in the supplied paths.
|
||||||
This invokes the find() method for each Compiler class,
|
This invokes the find() method for each Compiler class,
|
||||||
and appends the compilers detected to a list.
|
and appends the compilers detected to a list.
|
||||||
"""
|
"""
|
||||||
if not paths:
|
paths = executable_search_paths(path_hints or get_path('PATH'))
|
||||||
paths = get_path('PATH')
|
|
||||||
# Make sure path elements exist, and include /bin directories
|
|
||||||
# under prefixes.
|
|
||||||
filtered_path = []
|
|
||||||
for p in paths:
|
|
||||||
# Eliminate symlinks and just take the real directories.
|
|
||||||
p = os.path.realpath(p)
|
|
||||||
if not os.path.isdir(p):
|
|
||||||
continue
|
|
||||||
filtered_path.append(p)
|
|
||||||
|
|
||||||
# Check for a bin directory, add it if it exists
|
|
||||||
bin = os.path.join(p, 'bin')
|
|
||||||
if os.path.isdir(bin):
|
|
||||||
filtered_path.append(os.path.realpath(bin))
|
|
||||||
|
|
||||||
# Once the paths are cleaned up, do a search for each type of
|
# Once the paths are cleaned up, do a search for each type of
|
||||||
# compiler. We can spawn a bunch of parallel searches to reduce
|
# compiler. We can spawn a bunch of parallel searches to reduce
|
||||||
@ -261,7 +247,7 @@ def find_compilers(self, *paths):
|
|||||||
import spack.compilers
|
import spack.compilers
|
||||||
types = spack.compilers.all_compiler_types()
|
types = spack.compilers.all_compiler_types()
|
||||||
compiler_lists = mp.parmap(
|
compiler_lists = mp.parmap(
|
||||||
lambda cmp_cls: self.find_compiler(cmp_cls, *filtered_path),
|
lambda cmp_cls: self.find_compiler(cmp_cls, *paths),
|
||||||
types)
|
types)
|
||||||
|
|
||||||
# ensure all the version calls we made are cached in the parent
|
# ensure all the version calls we made are cached in the parent
|
||||||
@ -319,10 +305,10 @@ def find_compiler(self, cmp_cls, *path):
|
|||||||
return list(compilers.values())
|
return list(compilers.values())
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
d = {}
|
return {
|
||||||
d['name'] = self.name
|
'name': self.name,
|
||||||
d['version'] = self.version
|
'version': self.version
|
||||||
return d
|
}
|
||||||
|
|
||||||
|
|
||||||
@key_ordering
|
@key_ordering
|
||||||
@ -493,3 +479,30 @@ def sys_type():
|
|||||||
"""
|
"""
|
||||||
arch = Arch(platform(), 'default_os', 'default_target')
|
arch = Arch(platform(), 'default_os', 'default_target')
|
||||||
return str(arch)
|
return str(arch)
|
||||||
|
|
||||||
|
|
||||||
|
def executable_search_paths(path_hints):
|
||||||
|
"""Given a list of path hints returns a list of paths where
|
||||||
|
to search for an executable.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
path_hints (list of paths): list of paths taken into
|
||||||
|
consideration for a search
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A list containing the real path of every existing directory
|
||||||
|
in `path_hints` and its `bin` subdirectory if it exists.
|
||||||
|
"""
|
||||||
|
# Select the realpath of existing directories
|
||||||
|
existing_paths = filter(os.path.isdir, map(os.path.realpath, path_hints))
|
||||||
|
|
||||||
|
# Adding their 'bin' subdirectory
|
||||||
|
def maybe_add_bin(path):
|
||||||
|
bin_subdirectory = os.path.realpath(os.path.join(path, 'bin'))
|
||||||
|
if os.path.isdir(bin_subdirectory):
|
||||||
|
return [path, bin_subdirectory]
|
||||||
|
return [path]
|
||||||
|
|
||||||
|
return list(itertools.chain.from_iterable(
|
||||||
|
map(maybe_add_bin, existing_paths))
|
||||||
|
)
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
import spack.spec
|
import spack.spec
|
||||||
import spack.architecture
|
import spack.architecture
|
||||||
from spack.util.executable import Executable, ProcessError
|
from spack.util.executable import Executable, ProcessError
|
||||||
from spack.util.environment import get_path
|
|
||||||
|
|
||||||
__all__ = ['Compiler']
|
__all__ = ['Compiler']
|
||||||
|
|
||||||
@ -263,9 +262,6 @@ def _find_matches_in_path(cls, compiler_names, detect_version, *path):
|
|||||||
suffix, version) tuples. This can be further organized by
|
suffix, version) tuples. This can be further organized by
|
||||||
find().
|
find().
|
||||||
"""
|
"""
|
||||||
if not path:
|
|
||||||
path = get_path('PATH')
|
|
||||||
|
|
||||||
prefixes = [''] + cls.prefixes
|
prefixes = [''] + cls.prefixes
|
||||||
suffixes = [''] + cls.suffixes
|
suffixes = [''] + cls.suffixes
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
"""This module contains functions related to finding compilers on the
|
"""This module contains functions related to finding compilers on the
|
||||||
system and configuring Spack to use multiple compilers.
|
system and configuring Spack to use multiple compilers.
|
||||||
"""
|
"""
|
||||||
|
import itertools
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from llnl.util.lang import list_modules
|
from llnl.util.lang import list_modules
|
||||||
@ -177,17 +178,20 @@ def all_compiler_specs(scope=None, init_config=True):
|
|||||||
|
|
||||||
|
|
||||||
def find_compilers(*paths):
|
def find_compilers(*paths):
|
||||||
"""Return a list of compilers found in the supplied paths.
|
"""List of compilers found in the supplied paths.
|
||||||
This invokes the find_compilers() method for each operating
|
|
||||||
system associated with the host platform, and appends
|
This function invokes the find_compilers() method for each operating
|
||||||
the compilers detected to a list.
|
system associated with the host platform.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
*paths: paths where to search for compilers
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of compilers found in the supplied paths
|
||||||
"""
|
"""
|
||||||
# Find compilers for each operating system class
|
return list(itertools.chain.from_iterable(
|
||||||
oss = all_os_classes()
|
o.find_compilers(*paths) for o in all_os_classes()
|
||||||
compiler_lists = []
|
))
|
||||||
for o in oss:
|
|
||||||
compiler_lists.extend(o.find_compilers(*paths))
|
|
||||||
return compiler_lists
|
|
||||||
|
|
||||||
|
|
||||||
def supported_compilers():
|
def supported_compilers():
|
||||||
|
Loading…
Reference in New Issue
Block a user