From f8782c46d7a5d1caa4fbdbaba9c83bf6c0fcaf08 Mon Sep 17 00:00:00 2001 From: Betsy McPhail Date: Thu, 10 Jun 2021 12:18:31 -0400 Subject: Windows: VS and CMake support Fix: Building packages with CMake is broken (#24241) vsInstallPaths needs to be renamed vs_install_paths (#24297) --- lib/spack/spack/detection/common.py | 2 +- lib/spack/spack/detection/path.py | 23 ++++++++++++--------- lib/spack/spack/operating_systems/windows_os.py | 27 +++++++++++++------------ 3 files changed, 29 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/detection/common.py b/lib/spack/spack/detection/common.py index f5950f7467..f3ebd7aa11 100644 --- a/lib/spack/spack/detection/common.py +++ b/lib/spack/spack/detection/common.py @@ -141,7 +141,7 @@ def executable_prefix(executable_dir): components = executable_dir.split(os.sep) if 'bin' not in components: - return None + return executable_dir idx = components.index('bin') return os.sep.join(components[:idx]) diff --git a/lib/spack/spack/detection/path.py b/lib/spack/spack/detection/path.py index 8db209f009..f280af4520 100644 --- a/lib/spack/spack/detection/path.py +++ b/lib/spack/spack/detection/path.py @@ -41,17 +41,22 @@ def executables_in_path(path_hints=None): path_hints (list): list of paths to be searched. If None the list will be constructed based on the PATH environment variable. """ - # build_environment.py::1013: If we're on a Windows box, run vswhere, steal the installationPath using - # windows_os.py logic, construct paths to CMake and Ninja, add to PATH + # build_environment.py::1013: If we're on a Windows box, run vswhere, + # steal the installationPath using windows_os.py logic, + # construct paths to CMake and Ninja, add to PATH path_hints = path_hints or spack.util.environment.get_path('PATH') if sys.platform == 'win32': - msvcPaths = winOs.WindowsOs.vsInstallPaths - msvcCMakePaths = [os.path.join(path, "Common7", "IDE", "CommonExtensions", "Microsoft", "CMake", "CMake", "bin") - for path in msvcPaths] - [path_hints.insert(0, path) for path in msvcCMakePaths] - msvcNinjaPaths = [os.path.join(path, "Common7", "IDE", "CommonExtensions", "Microsoft", "CMake", "Ninja") - for path in msvcPaths] - [path_hints.insert(0, path) for path in msvcNinjaPaths] + msvc_paths = winOs.WindowsOs.vs_install_paths + msvc_cmake_paths = [ + os.path.join(path, "Common7", "IDE", "CommonExtensions", "Microsoft", + "CMake", "CMake", "bin") + for path in msvc_paths] + path_hints = msvc_cmake_paths + path_hints + msvc_ninja_paths = [ + os.path.join(path, "Common7", "IDE", "CommonExtensions", "Microsoft", + "CMake", "Ninja") + for path in msvc_paths] + path_hints = msvc_ninja_paths + path_hints search_paths = llnl.util.filesystem.search_paths_for_executables(*path_hints) diff --git a/lib/spack/spack/operating_systems/windows_os.py b/lib/spack/spack/operating_systems/windows_os.py index 91b7ddb678..7d5937c4a9 100755 --- a/lib/spack/spack/operating_systems/windows_os.py +++ b/lib/spack/spack/operating_systems/windows_os.py @@ -3,13 +3,15 @@ # # SPDX-License-Identifier: (Apache-2.0 OR MIT) -import sys +import glob import os import subprocess -import glob +import sys + from spack.architecture import OperatingSystem from spack.version import Version + # FIXME: To get the actual Windows version, we need a python that runs # natively on Windows, not Cygwin. def windows_version(): @@ -27,8 +29,8 @@ class WindowsOs(OperatingSystem): """ # Find MSVC directories using vswhere - compSearchPaths = [] - vsInstallPaths = [] + comp_search_paths = [] + vs_install_paths = [] root = os.environ.get('ProgramFiles(x86)') or os.environ.get('ProgramFiles') if root: try: @@ -42,14 +44,14 @@ class WindowsOs(OperatingSystem): "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", "-property", "installationPath", "-products", "*", - ], **extra_args).strip() + ], **extra_args).strip() # type: ignore[call-overload] if (3, 0) <= sys.version_info[:2] <= (3, 5): paths = paths.decode() - vsInstallPaths = paths.split('\n') - msvcPaths = [os.path.join(path, "VC", "Tools", "MSVC") - for path in vsInstallPaths] - for p in msvcPaths: - compSearchPaths.extend( + vs_install_paths = paths.split('\n') + msvc_paths = [os.path.join(path, "VC", "Tools", "MSVC") + for path in vs_install_paths] + for p in msvc_paths: + comp_search_paths.extend( glob.glob(os.path.join(p, '*', 'bin', 'Hostx64', 'x64'))) if os.getenv("ONEAPI_ROOT"): comp_search_paths.extend(glob.glob(os.path.join( @@ -58,9 +60,8 @@ class WindowsOs(OperatingSystem): 'windows', 'bin'))) except (subprocess.CalledProcessError, OSError, UnicodeDecodeError): pass - if compSearchPaths: - compiler_search_paths = compSearchPaths - # print(vsInstallPaths) + if comp_search_paths: + compiler_search_paths = comp_search_paths def __init__(self): super(WindowsOs, self).__init__('Windows10', '10') -- cgit v1.2.3-60-g2f50