# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
__author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCommon.py 0.8.D001 2004/07/15 06:24:14 knight"
-__version__ = "0.8"
+__revision__ = "TestCommon.py 0.9.D001 2004/08/06 08:19:26 knight"
+__version__ = "0.9"
import os
import os.path
pathname will be constructed by concatenating them. Exits FAILED
if any of the files does not exist.
"""
- files = map(lambda x: is_List(x) and os.path.join(x) or x, files)
+ files = map(lambda x: is_List(x) and apply(os.path.join, x) or x, files)
missing = filter(lambda x: not os.path.exists(x), files)
if missing:
print "Missing files: `%s'" % string.join(missing, "', `")
which case the pathname will be constructed by concatenating them.
Exits FAILED if any of the files exists.
"""
- files = map(lambda x: is_List(x) and os.path.join(x) or x, files)
+ files = map(lambda x: is_List(x) and apply(os.path.join, x) or x, files)
existing = filter(os.path.exists, files)
if existing:
print "Unexpected files exist: `%s'" % string.join(existing, "', `")
moc = target[0]
cpp = source[0]
# looks like cpp.includes is cleared before the build stage :-(
- includes = SCons.Defaults.CScan(cpp, env)
+ # not really sure about the path transformations (moc.cwd? cpp.cwd?) :-/
+ path = SCons.Defaults.CScan.path_function(env, moc.cwd)
+ includes = SCons.Defaults.CScan(cpp, env, path)
if not moc in includes:
SCons.Warnings.warn(
GeneratedMocFileNotIncluded,
"Generated moc file '%s' is not included by '%s'" %
(str(moc), str(cpp)))
+def find_file(filename, paths, node_factory):
+ retval = None
+ for dir in paths:
+ node = node_factory(filename, dir)
+ if node.rexists():
+ return node
+ return None
+
class _Automoc:
"""
Callable class, which works as an emitter for Programs, SharedLibraries and
splitext = SCons.Util.splitext
objBuilder = getattr(env, self.objBuilderName)
- # To make the following work, we assume that we stay in the
- # root directory
- #old_os_cwd = os.getcwd()
- #old_fs_cwd = FS.getcwd()
- #FS.chdir(FS.Dir('#'), change_os_dir=1)
-
# some regular expressions:
# Q_OBJECT detection
q_object_search = re.compile(r'[^A-Za-z0-9]Q_OBJECT[^A-Za-z0-9]')
# cxx and c comment 'eater'
- comment = re.compile(r'(//.*)|(/\*(([^*])|(\*[^/]))*\*/)')
-
+ #comment = re.compile(r'(//.*)|(/\*(([^*])|(\*[^/]))*\*/)')
+ # CW: something must be wrong with the regexp. See also bug #998222
+ # CURRENTLY THERE IS NO TEST CASE FOR THAT
+
# The following is kind of hacky to get builders working properly (FIXME)
objBuilderEnv = objBuilder.env
objBuilder.env = env
print "scons: qt: '%s' is no cxx file. Discarded." % str(cpp)
# c or fortran source
continue
- cpp_contents = comment.sub('', cpp.get_contents())
+ #cpp_contents = comment.sub('', cpp.get_contents())
+ cpp_contents = cpp.get_contents()
h=None
for h_ext in header_extensions:
# try to find the header file in the corresponding source
# directory
hname = splitext(cpp.name)[0] + h_ext
- h = SCons.Node.FS.find_file(hname,
- (cpp.get_dir(),),
- FS.File)
+ h = find_file(hname,
+ (cpp.get_dir(),),
+ FS.File)
if h:
if debug:
print "scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp))
- h_contents = comment.sub('', h.get_contents())
+ #h_contents = comment.sub('', h.get_contents())
+ h_contents = h.get_contents()
break
if not h and debug:
print "scons: qt: no header for '%s'." % (str(cpp))
objBuilder.env = objBuilderEnv
env.Moc.env = mocBuilderEnv
- #os.chdir(old_os_cwd)
- #FS.chdir(old_fs_cwd)
-
return (target, out_sources)
AutomocShared = _Automoc('SharedObject')
def uicEmitter(target, source, env):
adjustixes = SCons.Util.adjustixes
- bs = SCons.Util.splitext(str(source[0]))[0]
+ bs = SCons.Util.splitext(str(source[0].name))[0]
+ bs = os.path.join(str(target[0].get_dir()),bs)
# first target (header) is automatically added by builder
if len(target) < 2:
# second target is implementation
QT_MOC = r'%s',
QT_UIC = r'%s',
tools=['default','qt'])
+dup = 1
if ARGUMENTS.get('build_dir', 0):
if ARGUMENTS.get('chdir', 0):
SConscriptChdir(1)
else:
SConscriptChdir(0)
- BuildDir('build', '.', duplicate=1)
- sconscript = Dir('build').File('SConscript')
+ dup=int(ARGUMENTS.get('dup', 1))
+ if dup == 0:
+ builddir = 'build_dup0'
+ env['QT_DEBUG'] = 1
+ else:
+ builddir = 'build'
+ BuildDir(builddir, '.', duplicate=dup)
+ print builddir, dup
+ sconscript = Dir(builddir).File('SConscript')
else:
sconscript = File('SConscript')
-Export("env")
+Export("env dup")
SConscript( sconscript )
""" % (QT, QT_LIB, QT_MOC, QT_UIC))
test.fail_test( not os.path.exists(test.workpath('work1', 'build', moc)) )
+test.run(chdir='work1',
+ arguments = "build_dir=1 chdir=1 dup=0 " +
+ test.workpath('work1', 'build_dup0', aaa_exe) )
+test.must_exist(['work1', 'build_dup0', moc],
+ ['work1', 'build_dup0', aaa_exe])
+
##############################################################################
# 2. create .cpp, .h, moc_....cpp from .ui file
createSConstruct(test, ['work2', 'SConstruct'])
test.write(['work2', 'SConscript'], """
-Import("env")
+Import("env dup")
+if dup == 0: env.Append(CPPPATH=['#', '.'])
env.SharedLibrary(target = 'aaa', source = ['aaa.ui', 'useit.cpp'])
""")
test.up_to_date(chdir='work2', options = '-n', arguments = cpp)
test.up_to_date(chdir='work2', options = '-n', arguments = h)
test.up_to_date(chdir='work2', options = '-n', arguments = moc)
+# clean up
+test.run(chdir='work2', arguments = '-c ' + aaa_dll)
test.run(chdir='work2',
arguments = "build_dir=1 " +
test.workpath('work2', 'build', aaa_dll) )
+test.fail_test(not os.path.exists(test.workpath('work2','build',moc)) or
+ not os.path.exists(test.workpath('work2','build',cpp)) or
+ not os.path.exists(test.workpath('work2','build',h)) or
+ os.path.exists(test.workpath('work2', moc)) or
+ os.path.exists(test.workpath('work2', cpp)) or
+ os.path.exists(test.workpath('work2', h)))
test.run(chdir='work2',
arguments = "build_dir=1 chdir=1 " +
test.workpath('work2', 'build', aaa_dll) )
-
test.fail_test(not os.path.exists(test.workpath('work2','build',moc)) or
not os.path.exists(test.workpath('work2','build',cpp)) or
- not os.path.exists(test.workpath('work2','build',h)))
+ not os.path.exists(test.workpath('work2','build',h)) or
+ os.path.exists(test.workpath('work2', moc)) or
+ os.path.exists(test.workpath('work2', cpp)) or
+ os.path.exists(test.workpath('work2', h)))
+
+test.run(chdir='work2',
+ arguments = "build_dir=1 chdir=1 dup=0 " +
+ test.workpath('work2', 'build_dup0', aaa_dll) )
+
+test.must_exist(['work2','build_dup0',moc],
+ ['work2','build_dup0',cpp],
+ ['work2','build_dup0',h])
+test.must_not_exist(['work2', moc],
+ ['work2', cpp],
+ ['work2', h])
+
##############################################################################
# 3. create a moc file from a cpp file
createSConstruct(test, ['work3', 'SConstruct'])
test.write(['work3', 'SConscript'], """
-Import("env")
+Import("env dup")
+if dup == 0: env.Append(CPPPATH=['.'])
env.StaticLibrary(target = '%s', source = ['aaa.cpp','useit.cpp'])
""" % lib_aaa)
#include "%s"
""" % moc)
test.not_up_to_date(chdir='work3', options = '-n', arguments = moc)
+test.run(chdir='work3', options = '-c', arguments = lib_aaa)
test.run(chdir='work3',
arguments = "build_dir=1 " +
test.fail_test(not os.path.exists(test.workpath('work3', 'build', moc)))
+test.run(chdir='work3',
+ arguments = "build_dir=1 dup=0 " +
+ test.workpath('work3', 'build_dup0', lib_aaa) )
+test.must_exist(['work3', 'build_dup0', moc])
+
##############################################################################
# 4. Test with a copied environment.
os.environ['PATH']='.'
test.run(chdir='work7', stderr=None, arguments="-c test_realqt" + _exe)
- test.fail_test(not test.match_re(test.stderr(), r"""
+ test.fail_test(not test.match_re_dotall(test.stderr(), r""".*
scons: warning: Could not detect qt, using empty QTDIR
File "[^\"]*", line \d+, in .+
"""))
""")
test.run( arguments = "mytest" + _exe )
-
-def _existAll( test, files ):
- return reduce(lambda x,y: x and y,
- map(os.path.exists,map(test.workpath, files)))
-createSConstruct(test, ['SConstruct'],
- """QT_UICIMPLFLAGS='-x',
- QT_UICDECLFLAGS='-y',
- QT_MOCFROMHFLAGS='-z',
- QT_MOCFROMCXXFLAGS='-i -w',
- QT_UICDECLPREFIX='uic-',
- QT_UICDECLSUFFIX='.hpp',
- QT_UICIMPLPREFIX='',
- QT_UICIMPLSUFFIX='.cxx',
- QT_MOCHPREFIX='mmm',
- QT_MOCHSUFFIX='.cxx',
- QT_MOCCXXPREFIX='moc',
- QT_MOCCXXSUFFIX=`.inl',
- QT_UISUFFIX='.myui',""")
-
-test.fail_test(not _existAll(test, ['mmmmocFromH.cxx',
- 'mocmocFromCpp.inl',
- 'an_ui_file.cxx',
- 'uic-an_ui_file.hpp',
- 'mmman_ui_file.cxx',
- 'another_ui_file.cxx',
- 'uic-another_ui_file.hpp',
- 'mmmanother_ui_file.cxx']))
+test.must_exist('mmmmocFromH.cxx',
+ 'mocmocFromCpp.inl',
+ 'an_ui_file.cxx',
+ 'uic-an_ui_file.hpp',
+ 'mmman_ui_file.cxx',
+ 'another_ui_file.cxx',
+ 'uic-another_ui_file.hpp',
+ 'mmmanother_ui_file.cxx')
def _flagTest(test,fileToContentsStart):
import string