]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105776: Fix test_cppext when CC contains -std=c11 option (#108343)
authorVictor Stinner <vstinner@python.org>
Wed, 23 Aug 2023 02:52:56 +0000 (04:52 +0200)
committerGitHub <noreply@github.com>
Wed, 23 Aug 2023 02:52:56 +0000 (02:52 +0000)
Fix test_cppext when the C compiler command has the "-std=c11" option.
Remove "-std=" options from the compiler command.

Lib/test/test_cppext/setup.py
Misc/NEWS.d/next/Tests/2023-08-23-04-08-18.gh-issue-105776.oE6wp_.rst [new file with mode: 0644]

index 6867094a42043608ba3f279b5c4c7be8c6adc710..976633bc33889cd824aa01b244d816453cbd55f0 100644 (file)
@@ -1,7 +1,9 @@
 # gh-91321: Build a basic C++ test extension to check that the Python C API is
 # compatible with C++ and does not emit C++ compiler warnings.
 import os
+import shlex
 import sys
+import sysconfig
 
 from setuptools import setup, Extension
 
@@ -30,6 +32,17 @@ def main():
 
     cppflags = [*CPPFLAGS, f'-std={std}']
 
+    # 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 is not None:
+        cmd = shlex.split(cmd)
+        cmd = [arg for arg in cmd if not arg.startswith('-std=')]
+        cmd = shlex.join(cmd)
+        # CC env var overrides sysconfig CC variable in setuptools
+        os.environ['CC'] = cmd
+
     cpp_ext = Extension(
         name,
         sources=[SOURCE],
diff --git a/Misc/NEWS.d/next/Tests/2023-08-23-04-08-18.gh-issue-105776.oE6wp_.rst b/Misc/NEWS.d/next/Tests/2023-08-23-04-08-18.gh-issue-105776.oE6wp_.rst
new file mode 100644 (file)
index 0000000..0e0a3aa
--- /dev/null
@@ -0,0 +1,2 @@
+Fix test_cppext when the C compiler command ``-std=c11`` option: remove
+``-std=`` options from the compiler command. Patch by Victor Stinner.