Windows: VS and CMake support

Fix: Building packages with CMake is broken (#24241)

vsInstallPaths needs to be renamed vs_install_paths (#24297)
This commit is contained in:
Betsy McPhail 2021-06-10 12:18:31 -04:00 committed by Peter Scheibel
parent 15ef85e161
commit f8782c46d7
4 changed files with 33 additions and 30 deletions

View file

@ -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])

View file

@ -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)

View file

@ -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')

View file

@ -85,6 +85,3 @@ def install(self, spec, prefix):
if self.run_tests:
make('check')
make('install')