From fe0d1034aa07ce6c7acd106870b6a1da064bf6ba Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 25 Sep 2021 17:41:55 +0530 Subject: [PATCH] Cleanup any extra files produced by clang in debug mode when test compiling --- setup.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index ef47fd77a..57c63aa66 100755 --- a/setup.py +++ b/setup.py @@ -239,20 +239,20 @@ def test_compile( ldflags: Iterable[str] = (), ) -> bool: src = src or 'int main(void) { return 0; }' - with tempfile.NamedTemporaryFile(prefix='kitty-test-compile-') as f: + with tempfile.TemporaryDirectory(prefix='kitty-test-compile-') as tdir: p = subprocess.Popen( - [cc] + list(cflags) + ([] if link_also else ['-c']) + ['-x', lang, '-o', f.name, '-'] + + [cc] + list(cflags) + ([] if link_also else ['-c']) + ['-x', lang, '-o', os.path.join(tdir, 'dummy'), '-'] + [f'-l{x}' for x in libraries] + list(ldflags), stdout=subprocess.DEVNULL, stdin=subprocess.PIPE, stderr=None if show_stderr else subprocess.DEVNULL ) - stdin = p.stdin - assert stdin is not None - try: - stdin.write((src + '\n').encode('utf-8')) - stdin.close() - except BrokenPipeError: - return False - return p.wait() == 0 + stdin = p.stdin + assert stdin is not None + try: + stdin.write((src + '\n').encode('utf-8')) + stdin.close() + except BrokenPipeError: + return False + return p.wait() == 0 def first_successful_compile(cc: str, *cflags: str, src: Optional[str] = None, lang: str = 'c') -> str: