From 5b5b547398ae2ea2f57acb863f542a712cd970b7 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 23 Aug 2023 16:01:41 +0200 Subject: [PATCH] Fix setup.py when CC contains -std=c11 option (#70) Fix setup.py when the C compiler command has the "-std=c11" option. Remove "-std=" options from the compiler command. --- tests/setup.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/setup.py b/tests/setup.py index 1ee1e99..4deaa36 100755 --- a/tests/setup.py +++ b/tests/setup.py @@ -1,6 +1,15 @@ #!/usr/bin/env python3 import os.path +import shlex import sys +try: + from setuptools import setup, Extension +except ImportError: + from distutils.core import setup, Extension +try: + from distutils import sysconfig +except ImportError: + import sysconfig # C++ is only supported on Python 3.6 and newer @@ -43,10 +52,23 @@ def main(): - try: - from setuptools import setup, Extension - except ImportError: - from distutils.core import setup, Extension + # gh-105776: When "gcc -std=11" is used as the C++ compiler, -std=c11 + # option emits a C++ compiler warning. Remove "-std11" option from the + # CC command. + cmd = (sysconfig.get_config_var('CC') or '') + if cmd: + cmd = shlex.split(cmd) + cmd = [arg for arg in cmd if not arg.startswith('-std=')] + if (sys.version_info >= (3, 8)): + cmd = shlex.join(cmd) + elif (sys.version_info >= (3, 3)): + cmd = ' '.join(shlex.quote(arg) for arg in cmd) + else: + # Python 2.7 + import pipes + cmd = ' '.join(pipes.quote(arg) for arg in cmd) + # CC env var overrides sysconfig CC variable in setuptools + os.environ['CC'] = cmd cflags = ['-I' + SRC_DIR] cppflags = list(cflags)