Windows: Fix spack.bat handling of env commands (#35143)

This PR enables the successful execution of the spack binary cache
tutorial on Windows. It assumes gnupg and file are available (they
can be installed with choco).

* Fix handling of args with quotes in spack.bat
* `file` utility can be installed on Windows (e.g. with choco): update
  error message accordingly
This commit is contained in:
Dan Lipsa
2023-02-07 14:04:14 -05:00
committed by GitHub
parent 8358f430a4
commit 1648968514
2 changed files with 37 additions and 27 deletions

View File

@@ -23,7 +23,7 @@
from llnl.util.lang import dedupe, memoized
from llnl.util.symlink import islink, symlink
from spack.util.executable import CommandNotFoundError, Executable, which
from spack.util.executable import Executable, which
from spack.util.path import path_to_os_path, system_path_filter
is_windows = _platform == "win32"
@@ -117,13 +117,7 @@ def path_contains_subdirectory(path, root):
@memoized
def file_command(*args):
"""Creates entry point to `file` system command with provided arguments"""
try:
file_cmd = which("file", required=True)
except CommandNotFoundError as e:
if is_windows:
raise CommandNotFoundError("`file` utility is not available on Windows")
else:
raise e
file_cmd = which("file", required=True)
for arg in args:
file_cmd.add_default_arg(arg)
return file_cmd
@@ -134,7 +128,11 @@ def _get_mime_type():
"""Generate method to call `file` system command to aquire mime type
for a specified path
"""
return file_command("-b", "-h", "--mime-type")
if is_windows:
# -h option (no-dereference) does not exist in Windows
return file_command("-b", "--mime-type")
else:
return file_command("-b", "-h", "--mime-type")
@memoized