]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-116869: Fix test_cext on RHEL7 (#117010)
authorVictor Stinner <vstinner@python.org>
Tue, 19 Mar 2024 21:58:13 +0000 (22:58 +0100)
committerGitHub <noreply@github.com>
Tue, 19 Mar 2024 21:58:13 +0000 (22:58 +0100)
Remove -std option from CC command line.

Skip C++14 test for now on non-Windows platforms (like RHEL7).

Lib/test/test_cext/setup.py
Lib/test/test_cppext/__init__.py
Lib/test/test_cppext/setup.py

index d6c4410fa5f1e3ecb24139d52e70e7305cd24cc6..17a90caa98b5662212de248af32a04080a550dd8 100644 (file)
@@ -39,19 +39,22 @@ def main():
     if std:
         if support.MS_WINDOWS:
             cflags.append(f'/std:{std}')
-            std_prefix = '/std'
         else:
             cflags.append(f'-std={std}')
-            std_prefix = '-std'
 
-        # Remove existing -std options to only test ours
-        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_prefix)]
-            cmd = shlex.join(cmd)
-            # CC env var overrides sysconfig CC variable in setuptools
-            os.environ['CC'] = cmd
+    # Remove existing -std or /std options from CC command line.
+    # Python adds -std=c11 option.
+    cmd = (sysconfig.get_config_var('CC') or '')
+    if cmd is not None:
+        if support.MS_WINDOWS:
+            std_prefix = '/std'
+        else:
+            std_prefix = '-std'
+        cmd = shlex.split(cmd)
+        cmd = [arg for arg in cmd if not arg.startswith(std_prefix)]
+        cmd = shlex.join(cmd)
+        # CC env var overrides sysconfig CC variable in setuptools
+        os.environ['CC'] = cmd
 
     # Define Py_LIMITED_API macro
     if limited:
index b8414f217c7dde2c588c9d94ccab47888375dcc6..00a2840d49c77955593f0acb9f6e27eacb458474 100644 (file)
@@ -35,6 +35,9 @@ class TestCPPExt(unittest.TestCase):
     def test_build_cpp11(self):
         self.check_build('_testcpp11ext', std='c++11')
 
+    # Only test C++14 on MSVC.
+    # On s390x RHEL7, GCC 4.8.5 doesn't support C++14.
+    @unittest.skipIf(not support.MS_WINDOWS, "need Windows")
     def test_build_cpp14(self):
         self.check_build('_testcpp14ext', std='c++14')
 
index 77e47bcd0cbe1634ea71d2d2e0474d271d3561dc..80b3e0d5212f7bf84431351f3b433c469ec4bcc1 100644 (file)
@@ -35,19 +35,23 @@ def main():
     if std:
         if support.MS_WINDOWS:
             cppflags.append(f'/std:{std}')
-            std_prefix = '/std'
         else:
             cppflags.append(f'-std={std}')
-            std_prefix = '-std'
 
-        # Remove existing -std options to only test ours
-        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_prefix)]
-            cmd = shlex.join(cmd)
-            # CC env var overrides sysconfig CC variable in setuptools
-            os.environ['CC'] = cmd
+    # 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:
+        if support.MS_WINDOWS:
+            std_prefix = '/std'
+        else:
+            std_prefix = '-std'
+        cmd = shlex.split(cmd)
+        cmd = [arg for arg in cmd if not arg.startswith(std_prefix)]
+        cmd = shlex.join(cmd)
+        # CC env var overrides sysconfig CC variable in setuptools
+        os.environ['CC'] = cmd
 
     # On Windows, add PCbuild\amd64\ to include and library directories
     include_dirs = []