Added compiler detection for Cray front-end

This commit is contained in:
Massimiliano Culpo 2019-01-18 21:34:13 +01:00
parent fdeb9e43fa
commit 54313bbcc6
No known key found for this signature in database
GPG Key ID: D1ADB1014FF1118C
2 changed files with 64 additions and 43 deletions

View File

@ -205,7 +205,7 @@ def find_compilers(*path_hints):
# of arguments for each call. # of arguments for each call.
arguments = [] arguments = []
for o in all_os_classes(): for o in all_os_classes():
arguments.extend(arguments_to_detect_version_fn(o, *paths)) arguments.extend(arguments_to_detect_version_fn(o, paths))
# Here we map the function arguments to the corresponding calls # Here we map the function arguments to the corresponding calls
tp = multiprocessing.pool.ThreadPool() tp = multiprocessing.pool.ThreadPool()
@ -462,7 +462,7 @@ def all_compiler_types():
) )
def arguments_to_detect_version_fn(operating_system, *paths): def arguments_to_detect_version_fn(operating_system, paths, override=True):
"""Returns a list of DetectVersionArgs tuples to be used in a """Returns a list of DetectVersionArgs tuples to be used in a
corresponding function to detect compiler versions. corresponding function to detect compiler versions.
@ -472,14 +472,16 @@ def arguments_to_detect_version_fn(operating_system, *paths):
Args: Args:
operating_system (OperatingSystem): the operating system on which operating_system (OperatingSystem): the operating system on which
we are looking for compilers we are looking for compilers
*paths: paths to search for compilers paths: paths to search for compilers
override (bool): whether we should search for an override to this
function in the operating system class
Returns: Returns:
List of DetectVersionArgs tuples. Each item in the list will be later List of DetectVersionArgs tuples. Each item in the list will be later
mapped to the corresponding function call to detect the version of the mapped to the corresponding function call to detect the version of the
compilers in this OS. compilers in this OS.
""" """
def _default(*search_paths): def _default(search_paths):
command_arguments = [] command_arguments = []
files_to_be_tested = fs.files_in(*search_paths) files_to_be_tested = fs.files_in(*search_paths)
for compiler_name in spack.compilers.supported_compilers(): for compiler_name in spack.compilers.supported_compilers():
@ -509,8 +511,12 @@ def _default(*search_paths):
# does not spoil the intended precedence. # does not spoil the intended precedence.
return reversed(command_arguments) return reversed(command_arguments)
fn = getattr(operating_system, 'arguments_to_detect_version_fn', _default) fn = _default
return fn(*paths) if override:
fn = getattr(
operating_system, 'arguments_to_detect_version_fn', _default
)
return fn(paths)
def detect_version(detect_version_args): def detect_version(detect_version_args):

View File

@ -3,23 +3,19 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import contextlib
import os import os
import llnl.util.filesystem as fs
from spack.operating_systems.linux_distro import LinuxDistro from spack.operating_systems.linux_distro import LinuxDistro
from spack.util.environment import get_path
from spack.util.module_cmd import module from spack.util.module_cmd import module
class CrayFrontend(LinuxDistro): @contextlib.contextmanager
"""Represents OS that runs on login and service nodes of the Cray platform. def unload_programming_environment():
It acts as a regular Linux without Cray-specific modules and compiler """Context manager that unloads Cray Programming Environments."""
wrappers."""
def find_compilers(self, *paths):
"""Calls the overridden method but prevents it from detecting Cray
compiler wrappers to avoid possible false detections. The detected
compilers come into play only if a user decides to work with the Cray's
frontend OS as if it was a regular Linux environment."""
env_bu = None env_bu = None
# We rely on the fact that the PrgEnv-* modules set the PE_ENV # We rely on the fact that the PrgEnv-* modules set the PE_ENV
@ -43,12 +39,31 @@ def find_compilers(self, *paths):
# specified as prerequisites in the PrgEnv-* modulefiles. # specified as prerequisites in the PrgEnv-* modulefiles.
module('unload', prg_env) module('unload', prg_env)
# Call the overridden method. yield
clist = super(CrayFrontend, self).find_compilers(*paths)
# Restore the environment. # Restore the environment.
if env_bu is not None: if env_bu is not None:
os.environ.clear() os.environ.clear()
os.environ.update(env_bu) os.environ.update(env_bu)
return clist
class CrayFrontend(LinuxDistro):
"""Represents OS that runs on login and service nodes of the Cray platform.
It acts as a regular Linux without Cray-specific modules and compiler
wrappers."""
def arguments_to_detect_version_fn(self, paths):
"""Calls the default function but prevents it from detecting Cray
compiler wrappers to avoid possible false detections.
The detected compilers come into play only if a user decides to
work with the Cray's frontend OS as if it was a regular Linux
environment.
"""
import spack.compilers
with unload_programming_environment():
search_paths = fs.search_paths_for_executables(*get_path('PATH'))
args = spack.compilers.arguments_to_detect_version_fn(
self, search_paths, override=False
)
return args