Skip to content

Commit 3adf91b

Browse files
authored
Merge pull request #151 from IwakuraRein/scons-python3
Python 3 compatibility for building qt
2 parents ab5c7b0 + d7dc1c9 commit 3adf91b

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

data/scons/qt5.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,25 @@ def __call__(self, target, source, env):
135135
out_sources = source[:]
136136

137137
for obj in source:
138-
if isinstance(obj,basestring): # big kludge!
139-
print "scons: qt5: '%s' MAYBE USING AN OLD SCONS VERSION AND NOT CONVERTED TO 'File'. Discarded." % str(obj)
138+
if isinstance(obj,str): # big kludge!
139+
print("scons: qt5: '%s' MAYBE USING AN OLD SCONS VERSION AND NOT CONVERTED TO 'File'. Discarded." % str(obj))
140140
continue
141141
if not obj.has_builder():
142142
# binary obj file provided
143143
if debug:
144-
print "scons: qt: '%s' seems to be a binary. Discarded." % str(obj)
144+
print("scons: qt: '%s' seems to be a binary. Discarded." % str(obj))
145145
continue
146146
cpp = obj.sources[0]
147147
if not splitext(str(cpp))[1] in cxx_suffixes:
148148
if debug:
149-
print "scons: qt: '%s' is no cxx file. Discarded." % str(cpp)
149+
print("scons: qt: '%s' is no cxx file. Discarded." % str(cpp))
150150
# c or fortran source
151151
continue
152152
#cpp_contents = comment.sub('', cpp.get_contents())
153153
try:
154154
cpp_contents = cpp.get_contents()
155+
if not isinstance(cpp_contents, str):
156+
cpp_contents = str(cpp_contents)
155157
except: continue # may be an still not generated source
156158
h=None
157159
for h_ext in header_extensions:
@@ -161,27 +163,29 @@ def __call__(self, target, source, env):
161163
h = find_file(hname, (cpp.get_dir(),), env.File)
162164
if h:
163165
if debug:
164-
print "scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp))
166+
print("scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp)))
165167
#h_contents = comment.sub('', h.get_contents())
166168
h_contents = h.get_contents()
169+
if not isinstance(h_contents, str):
170+
h_contents = str(h_contents)
167171
break
168172
if not h and debug:
169-
print "scons: qt: no header for '%s'." % (str(cpp))
173+
print("scons: qt: no header for '%s'." % (str(cpp)))
170174
if h and q_object_search.search(h_contents):
171175
# h file with the Q_OBJECT macro found -> add moc_cpp
172176
moc_cpp = env.Moc5(h)
173177
moc_o = objBuilder(moc_cpp)
174178
out_sources.append(moc_o)
175179
#moc_cpp.target_scanner = SCons.Defaults.CScan
176180
if debug:
177-
print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp))
181+
print("scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp)))
178182
if cpp and q_object_search.search(cpp_contents):
179183
# cpp file with Q_OBJECT macro found -> add moc
180184
# (to be included in cpp)
181185
moc = env.Moc5(cpp)
182186
env.Ignore(moc, moc)
183187
if debug:
184-
print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(cpp), str(moc))
188+
print("scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(cpp), str(moc)))
185189
#moc.source_scanner = SCons.Defaults.CScan
186190
# restore the original env attributes (FIXME)
187191
objBuilder.env = objBuilderEnv
@@ -303,6 +307,8 @@ def recursiveFiles(basepath, path) :
303307
result.append(itemPath)
304308
return result
305309
contents = node.get_contents()
310+
if not isinstance(contents, str):
311+
contents = str(contents)
306312
includes = qrcinclude_re.findall(contents)
307313
qrcpath = os.path.dirname(node.path)
308314
dirs = [included for included in includes if os.path.isdir(os.path.join(qrcpath,included))]
@@ -475,4 +481,4 @@ def enable_modules(self, modules, debug=False, crosscompiling=False) :
475481
return
476482

477483
def exists(env):
478-
return _detect(env)
484+
return _detect(env)

src/mtsgui/SConscript

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ Import('env', 'os', 'glob', 'sys', 'hasQt', 'hasCollada', 'hasBreakpad', 'mainEn
33

44
# For running Uic & Moc (below)
55
def recursiveDirs(root) :
6-
return filter((lambda a : a.rfind(".svn") == -1), [a[0] for a in os.walk(root)])
6+
return list(filter((lambda a : a.rfind(".svn") == -1), [a[0] for a in os.walk(root)]))
77

8-
def unique(list) :
9-
return dict.fromkeys(list).keys()
8+
def unique(l) :
9+
return list(dict.fromkeys(l).keys())
1010

1111
def scanFiles(dir, accept=["*.cpp"], reject=[]) :
1212
sources = []
@@ -15,15 +15,15 @@ def scanFiles(dir, accept=["*.cpp"], reject=[]) :
1515
for pattern in accept :
1616
sources+=glob.glob(path + "/" + pattern)
1717
for pattern in reject:
18-
sources = filter((lambda a : a.rfind(pattern) == -1), sources)
19-
sources = map((lambda a : os.path.basename(a)), sources)
18+
sources = list(filter((lambda a : a.rfind(pattern) == -1), sources))
19+
sources = list(map((lambda a : os.path.basename(a)), sources))
2020
return unique(sources)
2121

2222

2323
if hasQt:
2424
qtEnv = mainEnv.Clone()
2525
qtEnv.Append(CPPPATH=['#src/mtsgui'])
26-
if qtEnv.has_key('QTINCLUDE'):
26+
if 'QTINCLUDE' in qtEnv:
2727
qtEnv.Prepend(CPPPATH=qtEnv['QTINCLUDE'])
2828
qtEnv.EnableQt5Modules(['QtGui', 'QtWidgets', 'QtCore', 'QtOpenGL', 'QtXml', 'QtXmlPatterns', 'QtNetwork'])
2929

@@ -51,9 +51,9 @@ if hasQt:
5151

5252
if hasCollada:
5353
qtSources += converter_objects
54-
if env.has_key('COLLADALIBDIR'):
54+
if 'COLLADALIBDIR' in env:
5555
qtEnv.Prepend(LIBPATH=env['COLLADALIBDIR'])
56-
if env.has_key('COLLADALIB'):
56+
if 'COLLADALIB' in env:
5757
qtEnv.Prepend(LIBS=env['COLLADALIB'])
5858

5959
if sys.platform == 'darwin':

0 commit comments

Comments
 (0)