diff options
author | James Smillie <83249606+jamessmillie@users.noreply.github.com> | 2024-10-07 17:05:23 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-07 16:05:23 -0700 |
commit | a09b9f06599ef12f8250608305e6b43404901f92 (patch) | |
tree | 3ea48cefc4cbdc69820875cffd8d15d0a48fc79f /lib | |
parent | 92d940b7f464c089fd8efeaab91fcebdf5980db5 (diff) | |
download | spack-a09b9f06599ef12f8250608305e6b43404901f92.tar.gz spack-a09b9f06599ef12f8250608305e6b43404901f92.tar.bz2 spack-a09b9f06599ef12f8250608305e6b43404901f92.tar.xz spack-a09b9f06599ef12f8250608305e6b43404901f92.zip |
Windows/Testing: enable `spack view` tests on Windows (#46335)
Enable tests for symlink-based views (this works with almost no
modifications to the view logic). View logic is not yet robust
for hardlink/junction-based views, so those are disabled for now
(both in the tests and as subcommands to `spack view`).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/view.py | 9 | ||||
-rw-r--r-- | lib/spack/spack/filesystem_view.py | 10 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/view.py | 20 |
3 files changed, 30 insertions, 9 deletions
diff --git a/lib/spack/spack/cmd/view.py b/lib/spack/spack/cmd/view.py index 103a6ffb0e..374aa570d2 100644 --- a/lib/spack/spack/cmd/view.py +++ b/lib/spack/spack/cmd/view.py @@ -33,6 +33,8 @@ All operations on views are performed via proxy objects such as YamlFilesystemView. """ +import sys + import llnl.util.tty as tty from llnl.util.link_tree import MergeConflictError @@ -178,7 +180,12 @@ def setup_parser(sp): def view(parser, args): - "Produce a view of a set of packages." + """Produce a view of a set of packages.""" + + if sys.platform == "win32" and args.action in ("hardlink", "hard"): + # Hard-linked views are not yet allowed on Windows. + # See https://github.com/spack/spack/pull/46335#discussion_r1757411915 + tty.die("Hard linking is not supported on Windows. Please use symlinks or copy methods.") specs = spack.cmd.parse_specs(args.specs) path = args.path[0] diff --git a/lib/spack/spack/filesystem_view.py b/lib/spack/spack/filesystem_view.py index 0e508a9bd8..2d5890c363 100644 --- a/lib/spack/spack/filesystem_view.py +++ b/lib/spack/spack/filesystem_view.py @@ -100,10 +100,12 @@ def view_copy( spack.relocate.relocate_text(files=[dst], prefixes=prefix_to_projection) - try: - os.chown(dst, src_stat.st_uid, src_stat.st_gid) - except OSError: - tty.debug(f"Can't change the permissions for {dst}") + # The os module on Windows does not have a chown function. + if sys.platform != "win32": + try: + os.chown(dst, src_stat.st_uid, src_stat.st_gid) + except OSError: + tty.debug(f"Can't change the permissions for {dst}") #: supported string values for `link_type` in an env, mapped to canonical values diff --git a/lib/spack/spack/test/cmd/view.py b/lib/spack/spack/test/cmd/view.py index 6c349fe68c..1c405728b4 100644 --- a/lib/spack/spack/test/cmd/view.py +++ b/lib/spack/spack/test/cmd/view.py @@ -4,9 +4,12 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) import os.path +import sys import pytest +from llnl.util.symlink import _windows_can_symlink + import spack.util.spack_yaml as s_yaml from spack.installer import PackageInstaller from spack.main import SpackCommand @@ -16,7 +19,16 @@ extensions = SpackCommand("extensions") install = SpackCommand("install") view = SpackCommand("view") -pytestmark = pytest.mark.not_on_windows("does not run on windows") +if sys.platform == "win32": + if not _windows_can_symlink(): + pytest.skip( + "Windows must be able to create symlinks to run tests.", allow_module_level=True + ) + # TODO: Skipping hardlink command testing on windows until robust checks can be added. + # See https://github.com/spack/spack/pull/46335#discussion_r1757411915 + commands = ["symlink", "add", "copy", "relocate"] +else: + commands = ["hardlink", "symlink", "hard", "add", "copy", "relocate"] def create_projection_file(tmpdir, projection): @@ -28,7 +40,7 @@ def create_projection_file(tmpdir, projection): return projection_file -@pytest.mark.parametrize("cmd", ["hardlink", "symlink", "hard", "add", "copy", "relocate"]) +@pytest.mark.parametrize("cmd", commands) def test_view_link_type(tmpdir, mock_packages, mock_archive, mock_fetch, install_mockery, cmd): install("libdwarf") viewpath = str(tmpdir.mkdir("view_{0}".format(cmd))) @@ -41,7 +53,7 @@ def test_view_link_type(tmpdir, mock_packages, mock_archive, mock_fetch, install assert os.path.islink(package_prefix) == is_link_cmd -@pytest.mark.parametrize("add_cmd", ["hardlink", "symlink", "hard", "add", "copy", "relocate"]) +@pytest.mark.parametrize("add_cmd", commands) def test_view_link_type_remove( tmpdir, mock_packages, mock_archive, mock_fetch, install_mockery, add_cmd ): @@ -55,7 +67,7 @@ def test_view_link_type_remove( assert not os.path.exists(bindir) -@pytest.mark.parametrize("cmd", ["hardlink", "symlink", "hard", "add", "copy", "relocate"]) +@pytest.mark.parametrize("cmd", commands) def test_view_projections(tmpdir, mock_packages, mock_archive, mock_fetch, install_mockery, cmd): install("libdwarf@20130207") |