From 558fad1630f0ae5f6e464030009cf09e705bb80e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 24 Sep 2021 08:31:16 +0530 Subject: [PATCH] Fix test_compile() with debug and clang on macOS --- setup.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 90d4c8c48..5ff759115 100755 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ import argparse import glob import json import os +import platform import re import runpy import shlex @@ -13,14 +14,14 @@ import shutil import subprocess import sys import sysconfig -import platform +import tempfile import time from contextlib import suppress from functools import partial from pathlib import Path from typing import ( - Callable, Dict, Iterable, Iterator, List, NamedTuple, Optional, - Sequence, Set, Tuple, Union + Callable, Dict, Iterable, Iterator, List, NamedTuple, Optional, Sequence, + Set, Tuple, Union ) from glfw import glfw # noqa @@ -238,11 +239,12 @@ def test_compile( ldflags: Iterable[str] = (), ) -> bool: src = src or 'int main(void) { return 0; }' - p = subprocess.Popen( - [cc] + list(cflags) + ([] if link_also else ['-c']) + ['-x', lang, '-o', os.devnull, '-'] + - [f'-l{x}' for x in libraries] + list(ldflags), - stdout=subprocess.DEVNULL, stdin=subprocess.PIPE, stderr=None if show_stderr else subprocess.DEVNULL - ) + with tempfile.NamedTemporaryFile() as f: + p = subprocess.Popen( + [cc] + list(cflags) + ([] if link_also else ['-c']) + ['-x', lang, '-o', f.name, '-'] + + [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: