[Python-checkins] [3.12] gh-105776: Fix test_cppext when CC contains -std=c11 option (GH-108343) (#108345)
Yhg1s
webhook-mailer at python.org
Wed Aug 23 07:45:40 EDT 2023
https://github.com/python/cpython/commit/0d6e657689c58cbd790dec2f71f0879e1ed3d4a3
commit: 0d6e657689c58cbd790dec2f71f0879e1ed3d4a3
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Yhg1s <thomas at python.org>
date: 2023-08-23T13:45:37+02:00
summary:
[3.12] gh-105776: Fix test_cppext when CC contains -std=c11 option (GH-108343) (#108345)
gh-105776: Fix test_cppext when CC contains -std=c11 option (GH-108343)
Fix test_cppext when the C compiler command has the "-std=c11" option.
Remove "-std=" options from the compiler command.
(cherry picked from commit 9173b2bbe13aeccc075b571da05c653a2a91de1b)
Co-authored-by: Victor Stinner <vstinner at python.org>
files:
A Misc/NEWS.d/next/Tests/2023-08-23-04-08-18.gh-issue-105776.oE6wp_.rst
M Lib/test/test_cppext/setup.py
diff --git a/Lib/test/test_cppext/setup.py b/Lib/test/test_cppext/setup.py
index 6867094a42043..976633bc33889 100644
--- a/Lib/test/test_cppext/setup.py
+++ b/Lib/test/test_cppext/setup.py
@@ -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
index 0000000000000..0e0a3aa9b11e6
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2023-08-23-04-08-18.gh-issue-105776.oE6wp_.rst
@@ -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.
More information about the Python-checkins
mailing list