Skip to content

Commit 34917b5

Browse files
committed
[lldb] Don't use NamedTemporaryFile to test compiler support
You cannot use a NamedTempFile with an external process because it may not be flushed to disk. The safest and most portable approach is to close the file, call the other process and then unlink the file manually. Presumably this works fine on Linux, but it fails on Darwin when targeting remote-linux. See https://bugs.python.org/issue29573
1 parent a7ac431 commit 34917b5

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

lldb/packages/Python/lldbsuite/test/dotest.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@
4545
from ..support import seven
4646

4747

48+
class OnDiskTempFile:
49+
def __init__(self):
50+
self.path = None
51+
52+
def __enter__(self):
53+
fd, path = tempfile.mkstemp()
54+
os.close(fd)
55+
self.path = path
56+
return self
57+
58+
def __exit__(self, exc_type, exc_val, exc_tb):
59+
if os.path.exists(self.path):
60+
os.remove(self.path)
61+
62+
4863
def is_exe(fpath):
4964
"""Returns true if fpath is an executable."""
5065
if fpath is None:
@@ -780,8 +795,8 @@ def canRunLibcxxTests():
780795
return True, "libc++ always present"
781796

782797
if platform == "linux":
783-
with tempfile.NamedTemporaryFile() as f:
784-
cmd = [configuration.compiler, "-xc++", "-stdlib=libc++", "-o", f.name, "-"]
798+
with OnDiskTempFile() as f:
799+
cmd = [configuration.compiler, "-xc++", "-stdlib=libc++", "-o", f.path, "-"]
785800
p = subprocess.Popen(
786801
cmd,
787802
stdin=subprocess.PIPE,
@@ -840,8 +855,8 @@ def canRunMsvcStlTests():
840855
if platform != "windows":
841856
return False, f"Don't know how to build with MSVC's STL on {platform}"
842857

843-
with tempfile.NamedTemporaryFile() as f:
844-
cmd = [configuration.compiler, "-xc++", "-o", f.name, "-E", "-"]
858+
with OnDiskTempFile() as f:
859+
cmd = [configuration.compiler, "-xc++", "-o", f.path, "-E", "-"]
845860
p = subprocess.Popen(
846861
cmd,
847862
stdin=subprocess.PIPE,

0 commit comments

Comments
 (0)