From f2824d64d91dd7a7c4ad3ab26ce15d339007b347 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Mon, 8 Apr 2019 19:25:11 +0200 Subject: [PATCH] OS can optionally provide search paths for compiler detection This permits to deal more neatly with peculiarities of Cray systems when detecting compilers. --- lib/spack/spack/compilers/__init__.py | 17 +++++++---------- .../spack/operating_systems/cray_frontend.py | 18 +++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/spack/spack/compilers/__init__.py b/lib/spack/spack/compilers/__init__.py index 2384db55353..919380f5f26 100644 --- a/lib/spack/spack/compilers/__init__.py +++ b/lib/spack/spack/compilers/__init__.py @@ -198,14 +198,15 @@ def find_compilers(*path_hints): """ # Turn the path hints into real paths that are to be searched path_hints = path_hints or get_path('PATH') - paths = fs.search_paths_for_executables(*path_hints) + 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(): - arguments.extend(arguments_to_detect_version_fn(o, paths)) + 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() @@ -462,7 +463,7 @@ def all_compiler_types(): ) -def arguments_to_detect_version_fn(operating_system, paths, override=True): +def arguments_to_detect_version_fn(operating_system, paths): """Returns a list of DetectVersionArgs tuples to be used in a corresponding function to detect compiler versions. @@ -473,8 +474,6 @@ def arguments_to_detect_version_fn(operating_system, paths, override=True): operating_system (OperatingSystem): the operating system on which we are looking 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: List of DetectVersionArgs tuples. Each item in the list will be later @@ -511,11 +510,9 @@ def _default(search_paths): # does not spoil the intended precedence. return reversed(command_arguments) - fn = _default - if override: - fn = getattr( - operating_system, 'arguments_to_detect_version_fn', _default - ) + fn = getattr( + operating_system, 'arguments_to_detect_version_fn', _default + ) return fn(paths) diff --git a/lib/spack/spack/operating_systems/cray_frontend.py b/lib/spack/spack/operating_systems/cray_frontend.py index 5c034b05cf8..1e8d9f41114 100644 --- a/lib/spack/spack/operating_systems/cray_frontend.py +++ b/lib/spack/spack/operating_systems/cray_frontend.py @@ -52,18 +52,14 @@ class CrayFrontend(LinuxDistro): 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. + @property + def compiler_search_paths(self): + """Calls the default function but unloads Cray's programming + environments first. - 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. + This prevents from detecting Cray compiler wrappers and avoids + possible false detections. """ - 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 + return search_paths