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) components = executable_dir.split(os.sep)
if 'bin' not in components: if 'bin' not in components:
return None return executable_dir
idx = components.index('bin') idx = components.index('bin')
return os.sep.join(components[:idx]) 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 path_hints (list): list of paths to be searched. If None the list will be
constructed based on the PATH environment variable. constructed based on the PATH environment variable.
""" """
# build_environment.py::1013: If we're on a Windows box, run vswhere, steal the installationPath using # build_environment.py::1013: If we're on a Windows box, run vswhere,
# windows_os.py logic, construct paths to CMake and Ninja, add to PATH # 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') path_hints = path_hints or spack.util.environment.get_path('PATH')
if sys.platform == 'win32': if sys.platform == 'win32':
msvcPaths = winOs.WindowsOs.vsInstallPaths msvc_paths = winOs.WindowsOs.vs_install_paths
msvcCMakePaths = [os.path.join(path, "Common7", "IDE", "CommonExtensions", "Microsoft", "CMake", "CMake", "bin") msvc_cmake_paths = [
for path in msvcPaths] os.path.join(path, "Common7", "IDE", "CommonExtensions", "Microsoft",
[path_hints.insert(0, path) for path in msvcCMakePaths] "CMake", "CMake", "bin")
msvcNinjaPaths = [os.path.join(path, "Common7", "IDE", "CommonExtensions", "Microsoft", "CMake", "Ninja") for path in msvc_paths]
for path in msvcPaths] path_hints = msvc_cmake_paths + path_hints
[path_hints.insert(0, path) for path in msvcNinjaPaths] 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) 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) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import sys import glob
import os import os
import subprocess import subprocess
import glob import sys
from spack.architecture import OperatingSystem from spack.architecture import OperatingSystem
from spack.version import Version from spack.version import Version
# FIXME: To get the actual Windows version, we need a python that runs # FIXME: To get the actual Windows version, we need a python that runs
# natively on Windows, not Cygwin. # natively on Windows, not Cygwin.
def windows_version(): def windows_version():
@ -27,8 +29,8 @@ class WindowsOs(OperatingSystem):
""" """
# Find MSVC directories using vswhere # Find MSVC directories using vswhere
compSearchPaths = [] comp_search_paths = []
vsInstallPaths = [] vs_install_paths = []
root = os.environ.get('ProgramFiles(x86)') or os.environ.get('ProgramFiles') root = os.environ.get('ProgramFiles(x86)') or os.environ.get('ProgramFiles')
if root: if root:
try: try:
@ -42,14 +44,14 @@ class WindowsOs(OperatingSystem):
"-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"-property", "installationPath", "-property", "installationPath",
"-products", "*", "-products", "*",
], **extra_args).strip() ], **extra_args).strip() # type: ignore[call-overload]
if (3, 0) <= sys.version_info[:2] <= (3, 5): if (3, 0) <= sys.version_info[:2] <= (3, 5):
paths = paths.decode() paths = paths.decode()
vsInstallPaths = paths.split('\n') vs_install_paths = paths.split('\n')
msvcPaths = [os.path.join(path, "VC", "Tools", "MSVC") msvc_paths = [os.path.join(path, "VC", "Tools", "MSVC")
for path in vsInstallPaths] for path in vs_install_paths]
for p in msvcPaths: for p in msvc_paths:
compSearchPaths.extend( comp_search_paths.extend(
glob.glob(os.path.join(p, '*', 'bin', 'Hostx64', 'x64'))) glob.glob(os.path.join(p, '*', 'bin', 'Hostx64', 'x64')))
if os.getenv("ONEAPI_ROOT"): if os.getenv("ONEAPI_ROOT"):
comp_search_paths.extend(glob.glob(os.path.join( comp_search_paths.extend(glob.glob(os.path.join(
@ -58,9 +60,8 @@ class WindowsOs(OperatingSystem):
'windows', 'bin'))) 'windows', 'bin')))
except (subprocess.CalledProcessError, OSError, UnicodeDecodeError): except (subprocess.CalledProcessError, OSError, UnicodeDecodeError):
pass pass
if compSearchPaths: if comp_search_paths:
compiler_search_paths = compSearchPaths compiler_search_paths = comp_search_paths
# print(vsInstallPaths)
def __init__(self): def __init__(self):
super(WindowsOs, self).__init__('Windows10', '10') super(WindowsOs, self).__init__('Windows10', '10')

View file

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