summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-02-06 20:08:52 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-02-16 09:47:08 -0500
commit9792c81663d8bef3abfe22cf45405d8d282afe08 (patch)
tree184bd2912c05478b2d4f100e3c0160351a59e0c0
parent9e851472e59950c9d7ada3224a5bf317c0a9dc1a (diff)
downloadhaskell-9792c81663d8bef3abfe22cf45405d8d282afe08.tar.gz
testsuite: Probe whether symlinks are usable on Windows
Closes #17706.
-rw-r--r--testsuite/driver/testutil.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/testsuite/driver/testutil.py b/testsuite/driver/testutil.py
index 62b76c75fd..4c2f3ffdee 100644
--- a/testsuite/driver/testutil.py
+++ b/testsuite/driver/testutil.py
@@ -1,6 +1,7 @@
import os
import subprocess
import shutil
+import tempfile
from pathlib import Path, PurePath
from term_color import Color, colored
@@ -82,7 +83,28 @@ def testing_metrics():
#
# We define the following function to make this magic more
# explicit/discoverable. You are encouraged to use it instead of os.symlink.
-if os.name == 'nt' and os.getenv('FORCE_SYMLINKS') == None:
+def symlinks_work() -> bool:
+ if os.getenv('FORCE_SYMLINKS') is not None:
+ return True
+ elif os.name == 'nt':
+ # On Windows we try to create a symlink to test whether symlinks are
+ # usable.
+ works = False
+ with tempfile.NamedTemporaryFile() as tmp:
+ try:
+ tmp.write('hello')
+ os.symlink(tmp.name, '__symlink-test')
+ works = True
+ except OSError as e:
+ print('Saw {} during symlink test; assuming symlinks do not work.'.format(e))
+ finally:
+ os.unlink('__symlink-test')
+
+ return works
+ else:
+ return True
+
+if not symlinks_work():
def link_or_copy_file(src: Path, dst: Path):
shutil.copyfile(str(src), str(dst))
else: