Skip to content

Commit 438de10

Browse files
authored
gh-116869: Fix test_cext on RHEL7 (#117010)
Remove -std option from CC command line. Skip C++14 test for now on non-Windows platforms (like RHEL7).
1 parent 2d17309 commit 438de10

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

Lib/test/test_cext/setup.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,22 @@ def main():
3939
if std:
4040
if support.MS_WINDOWS:
4141
cflags.append(f'/std:{std}')
42-
std_prefix = '/std'
4342
else:
4443
cflags.append(f'-std={std}')
45-
std_prefix = '-std'
4644

47-
# Remove existing -std options to only test ours
48-
cmd = (sysconfig.get_config_var('CC') or '')
49-
if cmd is not None:
50-
cmd = shlex.split(cmd)
51-
cmd = [arg for arg in cmd if not arg.startswith(std_prefix)]
52-
cmd = shlex.join(cmd)
53-
# CC env var overrides sysconfig CC variable in setuptools
54-
os.environ['CC'] = cmd
45+
# Remove existing -std or /std options from CC command line.
46+
# Python adds -std=c11 option.
47+
cmd = (sysconfig.get_config_var('CC') or '')
48+
if cmd is not None:
49+
if support.MS_WINDOWS:
50+
std_prefix = '/std'
51+
else:
52+
std_prefix = '-std'
53+
cmd = shlex.split(cmd)
54+
cmd = [arg for arg in cmd if not arg.startswith(std_prefix)]
55+
cmd = shlex.join(cmd)
56+
# CC env var overrides sysconfig CC variable in setuptools
57+
os.environ['CC'] = cmd
5558

5659
# Define Py_LIMITED_API macro
5760
if limited:

Lib/test/test_cppext/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def test_build_cpp03(self):
3535
def test_build_cpp11(self):
3636
self.check_build('_testcpp11ext', std='c++11')
3737

38+
# Only test C++14 on MSVC.
39+
# On s390x RHEL7, GCC 4.8.5 doesn't support C++14.
40+
@unittest.skipIf(not support.MS_WINDOWS, "need Windows")
3841
def test_build_cpp14(self):
3942
self.check_build('_testcpp14ext', std='c++14')
4043

Lib/test/test_cppext/setup.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,23 @@ def main():
3535
if std:
3636
if support.MS_WINDOWS:
3737
cppflags.append(f'/std:{std}')
38-
std_prefix = '/std'
3938
else:
4039
cppflags.append(f'-std={std}')
41-
std_prefix = '-std'
4240

43-
# Remove existing -std options to only test ours
44-
cmd = (sysconfig.get_config_var('CC') or '')
45-
if cmd is not None:
46-
cmd = shlex.split(cmd)
47-
cmd = [arg for arg in cmd if not arg.startswith(std_prefix)]
48-
cmd = shlex.join(cmd)
49-
# CC env var overrides sysconfig CC variable in setuptools
50-
os.environ['CC'] = cmd
41+
# gh-105776: When "gcc -std=11" is used as the C++ compiler, -std=c11
42+
# option emits a C++ compiler warning. Remove "-std11" option from the
43+
# CC command.
44+
cmd = (sysconfig.get_config_var('CC') or '')
45+
if cmd is not None:
46+
if support.MS_WINDOWS:
47+
std_prefix = '/std'
48+
else:
49+
std_prefix = '-std'
50+
cmd = shlex.split(cmd)
51+
cmd = [arg for arg in cmd if not arg.startswith(std_prefix)]
52+
cmd = shlex.join(cmd)
53+
# CC env var overrides sysconfig CC variable in setuptools
54+
os.environ['CC'] = cmd
5155

5256
# On Windows, add PCbuild\amd64\ to include and library directories
5357
include_dirs = []

0 commit comments

Comments
 (0)