Skip to content

Commit e78372f

Browse files
authored
Update the SIP support so we can deal with a broken RHEL-9. (#129)
There is more information in the patch. With this in place, we can use SIP to build rqt_gui_cpp plugins for RHEL-9. Signed-off-by: Chris Lalancette <[email protected]>
1 parent 6c8f9e3 commit e78372f

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

cmake/sip_configure.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
from distutils.spawn import find_executable
33
import os
44
import re
5+
import shutil
56
import subprocess
67
import sys
8+
import tempfile
79

810
import PyQt5
911
from PyQt5 import QtCore
@@ -111,16 +113,43 @@ def get_sip_dir_flags(config):
111113
if sys.platform == 'win32' and os.path.isdir(sip_bin):
112114
sip_bin += '.exe'
113115

114-
cmd = [
115-
sip_bin,
116-
'-c', build_dir,
117-
'-b', os.path.join(build_dir, build_file),
118-
'-I', sip_dir,
119-
'-w'
120-
]
121-
cmd += sip_flags.split(' ')
122-
cmd.append(sip_file)
123-
subprocess.check_call(cmd)
116+
# SIP4 has an incompatibility with Qt 5.15.6. In particular, Qt 5.15.6 uses a new SIP directive
117+
# called py_ssize_t_clean in QtCoremod.sip that SIP4 does not understand.
118+
#
119+
# Unfortunately, the combination of SIP4 and Qt 5.15.6 is common. Archlinux, Ubuntu 22.04
120+
# and RHEL-9 all have this combination. On Ubuntu 22.04, there is a custom patch to SIP4
121+
# to make it understand the py_ssize_t_clean tag, so the combination works. But on most
122+
# other platforms, it fails.
123+
#
124+
# To workaround this, copy all of the SIP files into a temporary directory, remove the offending
125+
# line, and then use that temporary directory as the include path. This is unnecessary on
126+
# Ubuntu 22.04, but shouldn't hurt anything there.
127+
with tempfile.TemporaryDirectory() as tmpdirname:
128+
shutil.copytree(sip_dir, tmpdirname, dirs_exist_ok=True)
129+
130+
output = ''
131+
with open(os.path.join(tmpdirname, 'QtCore', 'QtCoremod.sip'), 'r') as infp:
132+
for line in infp:
133+
if line.startswith('%Module(name='):
134+
result = re.sub(r', py_ssize_t_clean=True', '', line)
135+
output += result
136+
else:
137+
output += line
138+
139+
with open(os.path.join(tmpdirname, 'QtCore', 'QtCoremod.sip'), 'w') as outfp:
140+
outfp.write(output)
141+
142+
cmd = [
143+
sip_bin,
144+
'-c', build_dir,
145+
'-b', os.path.join(build_dir, build_file),
146+
'-I', tmpdirname,
147+
'-w'
148+
]
149+
cmd += sip_flags.split(' ')
150+
cmd.append(sip_file)
151+
152+
subprocess.check_call(cmd)
124153

125154
# Create the Makefile. The QtModuleMakefile class provided by the
126155
# pyqtconfig module takes care of all the extra preprocessor, compiler and

0 commit comments

Comments
 (0)