Skip to content

SCons: Python 3 compatibility #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 62 additions & 59 deletions build/SConscript.configure
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import re, multiprocessing

Import('sys', 'os', 'SCons', 'resources')
Expand All @@ -20,14 +21,14 @@ if parallelize == True:
SetOption('num_jobs', multiprocessing.cpu_count())

if not os.path.exists(configFile):
print '\nA configuration file must be selected! Have a look at http://www.mitsuba-renderer.org/docs.html'
print('\nA configuration file must be selected! Have a look at http://www.mitsuba-renderer.org/docs.html')
Exit(1)

needsBuildDependencies = (sys.platform == 'win32' or sys.platform == 'darwin')

if needsBuildDependencies and not os.path.exists(GetBuildPath('#dependencies')):
print '\nThe required build dependency files are missing. Please see the documentation'
print 'at http://www.mitsuba-renderer.org/docs.html for details on how to get them.\n'
print('\nThe required build dependency files are missing. Please see the documentation')
print('at http://www.mitsuba-renderer.org/docs.html for details on how to get them.\n')
Exit(1)

python_versions = ["2.6", "2.7", "3.0", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", "3.7"]
Expand Down Expand Up @@ -94,11 +95,11 @@ vars.Add('INTEL_COMPILER', 'Should the Intel C++ compiler be used?')

try:
env = Environment(options=vars, ENV = os.environ, tools=['default', 'qt5'], toolpath=['#data/scons'])
print 'Checking for Qt 5.x... yes'
print('Checking for Qt 5.x... yes')
hasQt = True
except Exception:
env = Environment(options=vars, ENV = os.environ, tools=['default'], toolpath=['#data/scons'])
print 'Unable to detect a Qt installation -- not building the GUI!'
print('Unable to detect a Qt installation -- not building the GUI!')
hasQt = False

hasCollada=True
Expand All @@ -108,19 +109,19 @@ env.Append(CPPPATH=env['BASEINCLUDE'])
env.Append(CPPFLAGS=[])
env.Append(LIBPATH=[])
env.Append(LIBS=env['BASELIB'])
if env.has_key('BOOSTINCLUDE'):
if 'BOOSTINCLUDE' in env:
env.Prepend(CPPPATH=env['BOOSTINCLUDE'])
if env.has_key('BOOSTLIBDIR'):
if 'BOOSTLIBDIR' in env:
env.Prepend(LIBPATH=env['BOOSTLIBDIR'])
if env.has_key('BOOSTLIB'):
if 'BOOSTLIB' in env:
env.Prepend(LIBS=env['BOOSTLIB'])
if env.has_key('BASELIBDIR'):
if 'BASELIBDIR' in env:
env.Append(LIBPATH=env['BASELIBDIR'])
if env.has_key('OEXRINCLUDE'):
if 'OEXRINCLUDE' in env:
env.Prepend(CPPPATH=env['OEXRINCLUDE'])
if env.has_key('OEXRLIBDIR'):
if 'OEXRLIBDIR' in env:
env.Prepend(LIBPATH=env['OEXRLIBDIR'])
if env.has_key('EIGENINCLUDE'):
if 'EIGENINCLUDE' in env:
env.Prepend(CPPPATH=env['EIGENINCLUDE'])

env.Decider('MD5-timestamp')
Expand All @@ -140,64 +141,64 @@ libPathPrevious = SCons.Util.semi_deepcopy(env['LIBPATH'])
cppFlagsPrevious = SCons.Util.semi_deepcopy(env['CPPFLAGS'])
cxxFlagsPrevious = SCons.Util.semi_deepcopy(env['CXXFLAGS'])

if env.has_key('PNGINCLUDE'):
if 'PNGINCLUDE' in env:
env.Prepend(CPPPATH=env['PNGINCLUDE'])
if env.has_key('PNGLIBDIR'):
if 'PNGLIBDIR' in env:
env.Prepend(LIBPATH=env['PNGLIBDIR'])
if env.has_key('JPEGINCLUDE'):
if 'JPEGINCLUDE' in env:
env.Prepend(CPPPATH=env['JPEGINCLUDE'])
if env.has_key('JPEGLIBDIR'):
if 'JPEGLIBDIR' in env:
env.Prepend(LIBPATH=env['JPEGLIBDIR'])
if env.has_key('OEXRFLAGS'):
if 'OEXRFLAGS' in env:
env.Prepend(CPPFLAGS=env['OEXRFLAGS'])
if env.has_key('OEXRINCLUDE'):
if 'OEXRINCLUDE' in env:
env.Prepend(CPPPATH=env['OEXRINCLUDE'])
if env.has_key('OEXRLIBDIR'):
if 'OEXRLIBDIR' in env:
env.Prepend(LIBPATH=env['OEXRLIBDIR'])
if env.has_key('XERCESINCLUDE'):
if 'XERCESINCLUDE' in env:
env.Prepend(CPPPATH=env['XERCESINCLUDE'])
if env.has_key('XERCESLIBDIR'):
if 'XERCESLIBDIR' in env:
env.Prepend(LIBPATH=env['XERCESLIBDIR'])
if env.has_key('GLINCLUDE'):
if 'GLINCLUDE' in env:
env.Prepend(CPPPATH=env['GLINCLUDE'])
if env.has_key('GLFLAGS'):
if 'GLFLAGS' in env:
env.Prepend(CPPFLAGS=env['GLFLAGS'])
if env.has_key('COLLADAINCLUDE'):
if 'COLLADAINCLUDE' in env:
env.Prepend(CPPPATH=env['COLLADAINCLUDE'])
if env.has_key('COLLADALIBDIR'):
if 'COLLADALIBDIR' in env:
env.Prepend(LIBPATH=env['COLLADALIBDIR'])
if env.has_key('FFTWINCLUDE'):
if 'FFTWINCLUDE' in env:
env.Prepend(CPPPATH=env['FFTWINCLUDE'])
if env.has_key('FFTWLIBDIR'):
if 'FFTWLIBDIR' in env:
env.Prepend(LIBPATH=env['FFTWLIBDIR'])

if not conf.CheckCXX():
print 'Could not compile a simple C++ fragment, verify that ' + \
print('Could not compile a simple C++ fragment, verify that ' + \
env['CXX'] + ' is installed! This could also mean that the ' + \
'Boost libraries are missing. The file "config.log" should ' + \
'contain more information.'
'contain more information.')
Exit(1)
if not conf.CheckCHeader(['png.h']):
print 'libpng is missing (install libpng12-dev for PNG I/O support)'
print('libpng is missing (install libpng12-dev for PNG I/O support)')
else:
env.Append(CPPDEFINES = [['MTS_HAS_LIBPNG', 1]] )

if not conf.CheckCHeader(['stdio.h', 'jpeglib.h']):
print 'libjpeg is missing (install libjpeg62-dev for JPEG I/O support)'
print('libjpeg is missing (install libjpeg62-dev for JPEG I/O support)')
else:
env.Append(CPPDEFINES = [['MTS_HAS_LIBJPEG', 1]] )

if not conf.CheckCXXHeader('ImfRgba.h'):
print 'OpenEXR is missing (install libopenexr-dev for OpenEXR I/O support)'
print('OpenEXR is missing (install libopenexr-dev for OpenEXR I/O support)')
else:
env.Append(CPPDEFINES = [['MTS_HAS_OPENEXR', 1]] )

if not conf.CheckCXXHeader('xercesc/dom/DOMLSParser.hpp'):
print 'Xerces-C++ 3.x must be installed (install libxerces-c-dev)!'
print('Xerces-C++ 3.x must be installed (install libxerces-c-dev)!')
Exit(1)
if not conf.CheckCXXHeader('dae.h'):
hasCollada = False
print 'COLLADA DOM is missing: not building the COLLADA importer'
print('COLLADA DOM is missing: not building the COLLADA importer')

hasBreakpad = '-DMTS_HAS_BREAKPAD' in env['CCFLAGS'] or 'MTS_HAS_BREAKPAD' in env['CXXFLAGS']

Expand All @@ -211,54 +212,54 @@ for ver in python_versions:
if conf.CheckCXXHeader('pyconfig.h'):
hasPython += [ ver ]
else:
print 'Python ' + ver + ' is missing: not building wrappers'
print('Python ' + ver + ' is missing: not building wrappers')
env['CPPPATH'][:] = [ x for x in env['CPPPATH'] if x not in includePath ]

if not conf.CheckCXXHeader('boost/version.hpp'):
print 'Boost is missing (install libboost-all-dev)!'
print('Boost is missing (install libboost-all-dev)!')
Exit(1)
if not conf.TryCompile("#include <boost/version.hpp>\n#if BOOST_VERSION < 104400\n#error Boost is outdated!\n#endif", ".cpp"):
print 'Boost is outdated (you will need version 1.44 or newer)!'
print('Boost is outdated (you will need version 1.44 or newer)!')
Exit(1)
if not conf.CheckCXXHeader('Eigen/Core'):
print 'Eigen 3.x is missing (install libeigen3-dev)!'
print('Eigen 3.x is missing (install libeigen3-dev)!')
Exit(1)
if not conf.CheckCXXHeader('fftw3.h'):
print 'FFTW3 not found (install for fast image convolution support)'
print('FFTW3 not found (install for fast image convolution support)')
else:
env.Append(CPPDEFINES = [['MTS_HAS_FFTW', 1]] )
if sys.platform == 'win32':
if not (conf.CheckCHeader(['windows.h', 'GL/gl.h']) \
and conf.CheckCHeader(['windows.h', 'GL/glu.h']) \
and conf.CheckCHeader(['windows.h', 'GL/gl.h', 'GL/glext.h'])):
print 'OpenGL headers are missing!'
print('OpenGL headers are missing!')
Exit(1)
if not conf.CheckCHeader('GL/glew.h'):
print 'GLEW headers are missing!'
print('GLEW headers are missing!')
Exit(1)
elif sys.platform == 'linux2':
if not (conf.CheckCHeader('GL/gl.h') and conf.CheckCHeader('GL/glu.h') and conf.CheckCHeader(['GL/gl.h', 'GL/glext.h'])):
print 'OpenGL headers are missing!'
print('OpenGL headers are missing!')
Exit(1)
if not conf.CheckCHeader('GL/glew.h'):
print 'GLEW headers are missing (install libglewmx1.5-dev)!'
print('GLEW headers are missing (install libglewmx1.5-dev)!')
Exit(1)
if not conf.CheckType('GLEWContext', '#include <GL/glew.h>'):
print 'GLEW-MX must be present!'
print('GLEW-MX must be present!')
Exit(1)
if not conf.TryCompile("#include <GL/glew.h>\n int i = GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV;", '.cpp'):
print 'Your version of GLEW-MX seems to be outdated!'
print('Your version of GLEW-MX seems to be outdated!')
Exit(1)
elif sys.platform == 'darwin':
if not (conf.CheckCHeader('OpenGL/gl.h') and conf.CheckCHeader('OpenGL/glu.h') and conf.CheckCHeader(['OpenGL/gl.h', 'OpenGL/glext.h'])):
print 'OpenGL headers are missing!'
print('OpenGL headers are missing!')
Exit(1)
if not conf.CheckCHeader('OpenGL/glew.h'):
print 'GLEW headers are missing!'
print('GLEW headers are missing!')
Exit(1)
if sys.platform == 'linux2':
if not (conf.CheckCHeader(['X11/Xlib.h', 'X11/extensions/xf86vmode.h'])):
print 'X Video Mode selection library headers are missing! (Install libxxf86vm-dev)'
print('X Video Mode selection library headers are missing! (Install libxxf86vm-dev)')
Exit(1)

env.Replace(CPPPATH=cppPathPrevious)
Expand All @@ -273,14 +274,16 @@ for line in file:
if line.startswith("#define MTS_VERSION "):
MTS_VERSION = line[21:len(line)-2]
if MTS_VERSION == "":
print 'could not be determined!'
print('could not be determined!')
Exit(1)
else:
print MTS_VERSION
print(MTS_VERSION)
Export('MTS_VERSION')

if needsBuildDependencies:
versionFilename = GetBuildPath('#dependencies/version')
versionFilename = GetBuildPath('#dependencies/version.txt')
if not os.path.exists(versionFilename):
versionFilename = GetBuildPath('#dependencies/version')
versionMismatch = False

if not os.path.exists(versionFilename):
Expand All @@ -293,14 +296,14 @@ if needsBuildDependencies:
versionMismatch = True

if versionMismatch:
print '\nThe dependency directory and your Mitsuba codebase have different version'
print 'numbers! Your copy of Mitsuba has version %s, whereas the dependencies ' % MTS_VERSION
print 'have version %s. Please bring them into sync, either by running\n' % depVersion
print '$ hg update -r v%s\n' % depVersion
print 'in the Mitsuba directory, or by running\n'
print '$ cd dependencies'
print '$ hg pull'
print '$ hg update -r v%s\n' % MTS_VERSION
print('\nThe dependency directory and your Mitsuba codebase have different version')
print('numbers! Your copy of Mitsuba has version %s, whereas the dependencies ' % MTS_VERSION)
print('have version %s. Please bring them into sync, either by running\n' % depVersion)
print('$ hg update -r v%s\n' % depVersion)
print('in the Mitsuba directory, or by running\n')
print('$ cd dependencies')
print('$ hg pull')
print('$ hg update -r v%s\n' % MTS_VERSION)
Exit(1)

env = conf.Finish()
Expand Down
3 changes: 2 additions & 1 deletion build/SConscript.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import fnmatch

Import('env', 'os', 'sys', 'plugins', 'dist',
Expand Down Expand Up @@ -27,7 +28,7 @@ def installAs(target, path, prefix = None):
return result

if not 'DISTDIR' in env:
print 'The \"DISTDIR\" variable is missing. Please update your configuration file!'
print('The \"DISTDIR\" variable is missing. Please update your configuration file!')
Exit(1)

distDir = env.GetBuildPath(env['DISTDIR'])
Expand Down
24 changes: 15 additions & 9 deletions data/scons/qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,25 @@ def __call__(self, target, source, env):
out_sources = source[:]

for obj in source:
if isinstance(obj,basestring): # big kludge!
print "scons: qt5: '%s' MAYBE USING AN OLD SCONS VERSION AND NOT CONVERTED TO 'File'. Discarded." % str(obj)
if isinstance(obj,str): # big kludge!
print("scons: qt5: '%s' MAYBE USING AN OLD SCONS VERSION AND NOT CONVERTED TO 'File'. Discarded." % str(obj))
continue
if not obj.has_builder():
# binary obj file provided
if debug:
print "scons: qt: '%s' seems to be a binary. Discarded." % str(obj)
print("scons: qt: '%s' seems to be a binary. Discarded." % str(obj))
continue
cpp = obj.sources[0]
if not splitext(str(cpp))[1] in cxx_suffixes:
if debug:
print "scons: qt: '%s' is no cxx file. Discarded." % str(cpp)
print("scons: qt: '%s' is no cxx file. Discarded." % str(cpp))
# c or fortran source
continue
#cpp_contents = comment.sub('', cpp.get_contents())
try:
cpp_contents = cpp.get_contents()
if not isinstance(cpp_contents, str):
cpp_contents = str(cpp_contents)
except: continue # may be an still not generated source
h=None
for h_ext in header_extensions:
Expand All @@ -161,27 +163,29 @@ def __call__(self, target, source, env):
h = find_file(hname, (cpp.get_dir(),), env.File)
if h:
if debug:
print "scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp))
print("scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp)))
#h_contents = comment.sub('', h.get_contents())
h_contents = h.get_contents()
if not isinstance(h_contents, str):
h_contents = str(h_contents)
break
if not h and debug:
print "scons: qt: no header for '%s'." % (str(cpp))
print("scons: qt: no header for '%s'." % (str(cpp)))
if h and q_object_search.search(h_contents):
# h file with the Q_OBJECT macro found -> add moc_cpp
moc_cpp = env.Moc5(h)
moc_o = objBuilder(moc_cpp)
out_sources.append(moc_o)
#moc_cpp.target_scanner = SCons.Defaults.CScan
if debug:
print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp))
print("scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp)))
if cpp and q_object_search.search(cpp_contents):
# cpp file with Q_OBJECT macro found -> add moc
# (to be included in cpp)
moc = env.Moc5(cpp)
env.Ignore(moc, moc)
if debug:
print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(cpp), str(moc))
print("scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(cpp), str(moc)))
#moc.source_scanner = SCons.Defaults.CScan
# restore the original env attributes (FIXME)
objBuilder.env = objBuilderEnv
Expand Down Expand Up @@ -303,6 +307,8 @@ def recursiveFiles(basepath, path) :
result.append(itemPath)
return result
contents = node.get_contents()
if not isinstance(contents, str):
contents = str(contents)
includes = qrcinclude_re.findall(contents)
qrcpath = os.path.dirname(node.path)
dirs = [included for included in includes if os.path.isdir(os.path.join(qrcpath,included))]
Expand Down Expand Up @@ -475,4 +481,4 @@ def enable_modules(self, modules, debug=False, crosscompiling=False) :
return

def exists(env):
return _detect(env)
return _detect(env)
6 changes: 3 additions & 3 deletions src/converter/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ if hasCollada:
# Build the COLLADA importer if COLLADA-DOM is vailable
colladaEnv.Append(LIBS=['mitsuba-hw'])
colladaEnv.Append(LIBPATH=['#src/libhw'])
if colladaEnv.has_key('COLLADAINCLUDE'):
if 'COLLADAINCLUDE' in colladaEnv:
colladaEnv.Prepend(CPPPATH=colladaEnv['COLLADAINCLUDE'])
if colladaEnv.has_key('COLLADALIBDIR'):
if 'COLLADALIBDIR' in colladaEnv:
colladaEnv.Prepend(LIBPATH=colladaEnv['COLLADALIBDIR'])
if colladaEnv.has_key('COLLADALIB'):
if 'COLLADALIB' in colladaEnv:
colladaEnv.Prepend(LIBS=colladaEnv['COLLADALIB'])
converter_objects += [
colladaEnv.StaticObject('collada.cpp'),
Expand Down
8 changes: 4 additions & 4 deletions src/films/SConscript
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Import('env', 'plugins')

filmEnv = env.Clone()
if filmEnv.has_key('OEXRLIBDIR'):
if 'OEXRLIBDIR' in filmEnv:
filmEnv.Prepend(LIBPATH=env['OEXRLIBDIR'])
if filmEnv.has_key('OEXRINCLUDE'):
if 'OEXRINCLUDE' in filmEnv:
filmEnv.Prepend(CPPPATH=env['OEXRINCLUDE'])
if filmEnv.has_key('OEXRFLAGS'):
if 'OEXRFLAGS' in filmEnv:
filmEnv.Prepend(CPPFLAGS=env['OEXRFLAGS'])
if filmEnv.has_key('OEXRLIB'):
if 'OEXRLIB' in filmEnv:
filmEnv.Prepend(LIBS=env['OEXRLIB'])

plugins += filmEnv.SharedLibrary('mfilm', ['mfilm.cpp', 'cnpy.cpp'])
Expand Down
Loading