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).
This commit is contained in:
Victor Stinner 2024-03-19 22:58:13 +01:00 committed by GitHub
parent 2d17309cc7
commit 438de10c16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 20 deletions

View File

@ -39,19 +39,22 @@ def main():
if std: if std:
if support.MS_WINDOWS: if support.MS_WINDOWS:
cflags.append(f'/std:{std}') cflags.append(f'/std:{std}')
std_prefix = '/std'
else: else:
cflags.append(f'-std={std}') cflags.append(f'-std={std}')
std_prefix = '-std'
# Remove existing -std options to only test ours # Remove existing -std or /std options from CC command line.
cmd = (sysconfig.get_config_var('CC') or '') # Python adds -std=c11 option.
if cmd is not None: cmd = (sysconfig.get_config_var('CC') or '')
cmd = shlex.split(cmd) if cmd is not None:
cmd = [arg for arg in cmd if not arg.startswith(std_prefix)] if support.MS_WINDOWS:
cmd = shlex.join(cmd) std_prefix = '/std'
# CC env var overrides sysconfig CC variable in setuptools else:
os.environ['CC'] = cmd 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 # Define Py_LIMITED_API macro
if limited: if limited:

View File

@ -35,6 +35,9 @@ class TestCPPExt(unittest.TestCase):
def test_build_cpp11(self): def test_build_cpp11(self):
self.check_build('_testcpp11ext', std='c++11') 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): def test_build_cpp14(self):
self.check_build('_testcpp14ext', std='c++14') self.check_build('_testcpp14ext', std='c++14')

View File

@ -35,19 +35,23 @@ def main():
if std: if std:
if support.MS_WINDOWS: if support.MS_WINDOWS:
cppflags.append(f'/std:{std}') cppflags.append(f'/std:{std}')
std_prefix = '/std'
else: else:
cppflags.append(f'-std={std}') cppflags.append(f'-std={std}')
std_prefix = '-std'
# Remove existing -std options to only test ours # gh-105776: When "gcc -std=11" is used as the C++ compiler, -std=c11
cmd = (sysconfig.get_config_var('CC') or '') # option emits a C++ compiler warning. Remove "-std11" option from the
if cmd is not None: # CC command.
cmd = shlex.split(cmd) cmd = (sysconfig.get_config_var('CC') or '')
cmd = [arg for arg in cmd if not arg.startswith(std_prefix)] if cmd is not None:
cmd = shlex.join(cmd) if support.MS_WINDOWS:
# CC env var overrides sysconfig CC variable in setuptools std_prefix = '/std'
os.environ['CC'] = cmd 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 # On Windows, add PCbuild\amd64\ to include and library directories
include_dirs = [] include_dirs = []