def compiler_search_paths(self):
        """Calls the default function but unloads Cray's programming
        environments first.

        This prevents from detecting Cray compiler wrappers and avoids
        possible false detections.
        """
        with unload_programming_environment():
            search_paths = fs.search_paths_for_executables(*get_path('PATH'))
        return search_paths
Beispiel #2
0
def find_compilers(path_hints=None):
    """Returns the list of compilers found in the paths given as arguments.

    Args:
        path_hints (list or None): list of path hints where to look for.
            A sensible default based on the ``PATH`` environment variable
            will be used if the value is None

    Returns:
        List of compilers found
    """
    if path_hints is None:
        path_hints = get_path('PATH')
    default_paths = fs.search_paths_for_executables(*path_hints)

    # To detect the version of the compilers, we dispatch a certain number
    # of function calls to different workers. Here we construct the list
    # of arguments for each call.
    arguments = []
    for o in all_os_classes():
        search_paths = getattr(o, 'compiler_search_paths', default_paths)
        arguments.extend(arguments_to_detect_version_fn(o, search_paths))

    # Here we map the function arguments to the corresponding calls
    tp = multiprocessing.pool.ThreadPool()
    try:
        detected_versions = tp.map(detect_version, arguments)
    finally:
        tp.close()

    def valid_version(item):
        value, error = item
        if error is None:
            return True
        try:
            # This will fail on Python 2.6 if a non ascii
            # character is in the error
            tty.debug(error)
        except UnicodeEncodeError:
            pass
        return False

    def remove_errors(item):
        value, _ = item
        return value

    return make_compiler_list(
        map(remove_errors, filter(valid_version, detected_versions))
    )
Beispiel #3
0
    def compiler_search_paths(self):
        """Calls the default function but unloads Cray's programming
        environments first.

        This prevents from detecting Cray compiler wrappers and avoids
        possible false detections.
        """
        import spack.compilers

        with unload_programming_environment():
            search_paths = get_path('PATH')

        extract_path_re = re.compile(r'prepend-path[\s]*PATH[\s]*([/\w\.:-]*)')

        for compiler_cls in spack.compilers.all_compiler_types():
            # Check if the compiler class is supported on Cray
            prg_env = getattr(compiler_cls, 'PrgEnv', None)
            compiler_module = getattr(compiler_cls, 'PrgEnv_compiler', None)
            if not (prg_env and compiler_module):
                continue

            # It is supported, check which versions are available
            output = module('avail', compiler_cls.PrgEnv_compiler)
            version_regex = r'({0})/([\d\.]+[\d]-?[\w]*)'.format(
                compiler_cls.PrgEnv_compiler
            )
            matches = re.findall(version_regex, output)
            versions = tuple(version for _, version in matches
                             if 'classic' not in version)

            # Now inspect the modules and add to paths
            msg = "[CRAY FE] Detected FE compiler [name={0}, versions={1}]"
            tty.debug(msg.format(compiler_module, versions))
            for v in versions:
                try:
                    current_module = compiler_module + '/' + v
                    out = module('show', current_module)
                    match = extract_path_re.search(out)
                    search_paths += match.group(1).split(':')
                except Exception as e:
                    msg = ("[CRAY FE] An unexpected error occurred while "
                           "detecting FE compiler [compiler={0}, "
                           " version={1}, error={2}]")
                    tty.debug(msg.format(compiler_cls.name, v, str(e)))

        search_paths = list(llnl.util.lang.dedupe(search_paths))
        return fs.search_paths_for_executables(*search_paths)