diff options
author | Steven Knight <knight@baldmt.com> | 2004-07-12 20:33:44 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2004-07-12 20:33:44 (GMT) |
commit | bb10501c96110a8f9a9068344c7f89e79e97fef2 (patch) | |
tree | 5a136a3e8fc5e26951471930ae036f53d88254e0 /test | |
parent | 1c1b7792121a066fc3cb9537879c71e86b676102 (diff) | |
download | SCons-bb10501c96110a8f9a9068344c7f89e79e97fef2.zip SCons-bb10501c96110a8f9a9068344c7f89e79e97fef2.tar.gz SCons-bb10501c96110a8f9a9068344c7f89e79e97fef2.tar.bz2 |
QT fixes and enhancements: Moc() and Uic() builders, a lot of new variables. (Christoph Wiedemann)
Diffstat (limited to 'test')
-rw-r--r-- | test/Object.py | 23 | ||||
-rw-r--r-- | test/QT.py | 336 | ||||
-rw-r--r-- | test/QTFLAGS.py | 69 | ||||
-rw-r--r-- | test/import.py | 11 |
4 files changed, 378 insertions, 61 deletions
diff --git a/test/Object.py b/test/Object.py index cde1391..9ed7a15 100644 --- a/test/Object.py +++ b/test/Object.py @@ -39,10 +39,11 @@ env = Environment() f1 = env.Object(target = 'f1', source = 'f1.c') f2 = Object(target = 'f2', source = 'f2.cpp') f3 = env.Object(target = 'f3', source = 'f3.c') -env.Program(target = 'prog1', source = Split('f1%s f2%s f3%s prog.cpp')) -env.Program(target = 'prog2', source = [f1, f2, f3, 'prog.cpp']) +mult_o = env.Object(['f4.c', 'f5.c']) +env.Program(target = 'prog1', source = Split('f1%s f2%s f3%s f4%s prog.cpp')) +env.Program(target = 'prog2', source = mult_o + [f1, f2, f3, 'prog.cpp']) env.Program(target = 'prog3', source = ['f1%s', f2, 'f3%s', 'prog.cpp']) -""" % (_obj, _obj, _obj, _obj, _obj)) +""" % (_obj, _obj, _obj, _obj, _obj, _obj)) test.write('f1.c', r""" void @@ -70,6 +71,22 @@ f3(void) } """) +test.write('f4.c', r""" +void +f4(void) +{ + printf("f4.c\n"); +} +""") + +test.write('f5.c', r""" +void +f5(void) +{ + printf("f5.c\n"); +} +""") + test.write('prog.cpp', r""" #include <stdio.h> @@ -30,6 +30,7 @@ generation of qt's moc files. """ import os.path +import re import string import TestSCons @@ -40,6 +41,7 @@ lib_ = TestSCons.lib_ _lib = TestSCons._lib dll_ = TestSCons.dll_ _dll = TestSCons._dll +_shobj = TestSCons._shobj test = TestSCons.TestSCons() @@ -72,6 +74,7 @@ sys.exit(0) test.write(['qt', 'bin', 'myuic.py'], """ import sys +import os.path import string output_arg = 0 impl_arg = 0 @@ -92,8 +95,13 @@ for arg in sys.argv[1:]: if source: sys.exit(1) source = open(arg, 'rb') + sourceFile = arg if impl: output.write( '#include "' + impl + '"\\n' ) + if string.find(source.read(), '// ui.h') != -1: + output.write( + '#include "' + + os.path.basename(os.path.splitext(sourceFile)[0]) + '.ui.h"\\n') else: output.write( '#include "my_qobject.h"\\n' + source.read() + " Q_OBJECT \\n" ) output.close() @@ -130,7 +138,9 @@ QT_UIC = '%s %s' % (python, test.workpath('qt','bin','myuic.py')) def createSConstruct(test,place): test.write(place, """ -env = Environment(QTDIR = r'%s', +if ARGUMENTS.get('noqtdir', 0): QTDIR=None +else: QTDIR=r'%s' +env = Environment(QTDIR = QTDIR, QT_LIB = r'%s', QT_MOC = r'%s', QT_UIC = r'%s', @@ -149,7 +159,11 @@ SConscript( sconscript ) """ % (QT, QT_LIB, QT_MOC, QT_UIC)) test.subdir( 'work1', 'work2', 'work3', 'work4', - 'work5', 'work6', 'work7', 'work8' ) + 'work5', 'work6', 'work7', 'work8', + 'work9', ['work9', 'local_include'], + 'work10', ['work10', 'sub'], ['work10', 'sub', 'local_include'], + 'work11', ['work11', 'include'], ['work11', 'ui'], + 'work12') ############################################################################## # 1. create a moc file from a header file. @@ -199,7 +213,8 @@ test.fail_test( not os.path.exists(test.workpath('work1', 'build', moc)) ) aaa_dll = dll_ + 'aaa' + _dll moc = 'moc_aaa.cc' -cpp = 'aaa.cc' +cpp = 'uic_aaa.cc' +obj = os.path.splitext(cpp)[0] + _shobj h = 'aaa.h' createSConstruct(test, ['work2', 'SConstruct']) @@ -209,7 +224,12 @@ env.SharedLibrary(target = 'aaa', source = ['aaa.ui', 'useit.cpp']) """) test.write(['work2', 'aaa.ui'], r""" -void aaa(void) +#if defined (_WIN32) || defined(__CYGWIN__) +#define DLLEXPORT __declspec(dllexport) +#else +#define DLLEXPORT +#endif +DLLEXPORT void aaa(void) """) test.write(['work2', 'useit.cpp'], r""" @@ -223,7 +243,12 @@ test.run(chdir='work2', arguments = aaa_dll) test.up_to_date(chdir='work2', options='-n',arguments = aaa_dll) test.write(['work2', 'aaa.ui'], r""" /* a change */ -void aaa(void) +#if defined (_WIN32) || defined(__CYGWIN__) +#define DLLEXPORT __declspec(dllexport) +#else +#define DLLEXPORT +#endif +DLLEXPORT void aaa(void) """) test.not_up_to_date(chdir='work2', options = '-n', arguments = moc) test.not_up_to_date(chdir='work2', options = '-n', arguments = cpp) @@ -232,7 +257,16 @@ test.run(chdir='work2', arguments = aaa_dll) test.write(['work2', 'aaa.ui.h'], r""" /* test dependency to .ui.h */ """) -test.not_up_to_date(chdir='work2', options = '-n', arguments = cpp) +test.write(['work2', 'aaa.ui'], r""" +void aaa(void) +// ui.h +""") +test.run(chdir='work2', arguments = aaa_dll) +test.write(['work2', 'aaa.ui.h'], r""" +/* changed */ +""") +test.not_up_to_date(chdir='work2', options = '-n', arguments = obj) +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) @@ -251,7 +285,7 @@ test.fail_test(not os.path.exists(test.workpath('work2','build',moc)) or # 3. create a moc file from a cpp file lib_aaa = lib_ + 'aaa' + _lib -moc = 'moc_aaa.cc' +moc = 'aaa.moc' createSConstruct(test, ['work3', 'SConstruct']) test.write(['work3', 'SConscript'], """ @@ -398,10 +432,13 @@ foo6(void) } """) -test.run(chdir='work6') +# we can receive warnings about a non detected qt (empty QTDIR) +# these are not critical, but maybe annoying +test.run(chdir='work6', stderr=None) main_exe = 'main' + _exe test.run(program = test.workpath('work6', main_exe), + stderr = None, stdout = 'qt/include/foo6.h\n') ############################################################################## @@ -465,7 +502,7 @@ class MyClass1 : public QObject { void mocFromCpp() { MyClass1 myclass; } -#include "moc_mocFromCpp.cpp" +#include "mocFromCpp.moc" """) test.write( ['work7', 'mocFromH.h'],""" @@ -522,50 +559,287 @@ int main() { QTDIR=os.environ['QTDIR'] del os.environ['QTDIR'] - test.run(chdir='work7', arguments="-c test_realqt" + _exe) - test.run(chdir='work7', arguments="PATH=%s/bin test_realqt%s"%(QTDIR,_exe)) + test.run(chdir='work7', stderr=None, arguments="-c test_realqt" + _exe) + test.fail_test(not test.match_re(test.stderr(), r""" +scons: warning: Could not detect qt, using empty QTDIR +File "SConstruct", line \d+, in .+ +""")) + + test.run(chdir='work7', stderr=None, + arguments="PATH=%s/bin test_realqt%s"%(QTDIR,_exe)) + + test.fail_test(not test.match_re(test.stderr(), r""" +scons: warning: Could not detect qt, using moc executable as a hint \(QTDIR=%s\) +File "SConstruct", line \d+, in .+ +""" % (re.escape(QTDIR)))) + else: print "Could not find QT, skipping test(s)." ############################################################################## -# 8. test the $QT_AUTOBUUILD_MOC_SOURCES variable +# 8. test the $QT_AUTOBUILD_MOC_SOURCES variable +# +# This has been removed, but I'm leaving the test here, commented out, +# in case we ever resurrect this functionality again in the future. +# +#aaa_dll = dll_ + 'aaa' + _dll +#moc = 'moc_aaa.cc' +# +#createSConstruct(test, ['work8', 'SConstruct']) +# +#test.write(['work8', 'SConscript'], """ +#Import("env") +#env = env.Copy(QT_AUTOBUILD_MOC_SOURCES = 0) +#env.SharedLibrary(target = 'aaa', source = ['aaa.ui', 'useit.cpp', 'aaa_function.cpp']) +#""") +# +#test.write(['work8', 'aaa.ui'], r""" +##if defined (_WIN32) || defined(__CYGWIN__) +##define DLLEXPORT __declspec(dllexport) +##else +##define DLLEXPORT +##endif +#DLLEXPORT void aaa(void) +#""") +# +#test.write(['work8', 'useit.cpp'], r""" +##include "aaa.h" +#void useit() { +# aaa(); +#} +#""") +# +#test.write(['work8', 'aaa_function.cpp'], r""" +##include "my_qobject.h" +##if defined (_WIN32) || defined(__CYGWIN__) +##define DLLEXPORT __declspec(dllexport) +##else +##define DLLEXPORT +##endif +#DLLEXPORT void aaa(void) +# { my_qt_symbol( "aaa_function.cpp\n" ); } +#""") +# +#test.run(chdir='work8', arguments = aaa_dll) +# +#test.must_not_exist(test.workpath('work8', moc)) +# +#test.write(['work8', 'SConscript'], """ +#Import("env") +#env = env.Copy(QT_AUTOBUILD_MOC_SOURCES = 1) +#env.SharedLibrary(target = 'aaa', source = ['aaa.ui', 'useit.cpp']) +#""") +# +#test.run(chdir='work8', arguments = aaa_dll) +# +#test.must_exist(test.workpath('work8', moc)) -aaa_dll = dll_ + 'aaa' + _dll -moc = 'moc_aaa.cc' +############################################################################## +# 9. test that an overwritten CPPPATH is working with generated files -createSConstruct(test, ['work8', 'SConstruct']) +# this is basically test 1, but with an additional include +aaa_exe = 'aaa' + _exe -test.write(['work8', 'SConscript'], """ +createSConstruct(test, ['work9', 'SConstruct']) +test.write( ['work9', 'SConscript'], """ Import("env") -env = env.Copy(QT_AUTOBUILD_MOC_SOURCES = 0) -env.SharedLibrary(target = 'aaa', source = ['aaa.ui', 'useit.cpp']) +env.Program(target = 'aaa', source = 'aaa.cpp', CPPPATH=['$CPPPATH', './local_include']) """) -test.write(['work8', 'aaa.ui'], r""" -void aaa(void) +test.write(['work9', 'aaa.cpp'], r""" +#include "aaa.h" +int main() { aaa(); return 0; } """) -test.write(['work8', 'useit.cpp'], r""" +test.write(['work9', 'aaa.h'], r""" +#include "my_qobject.h" +#include "local_include.h" +void aaa(void) Q_OBJECT; +""") + +test.write(['work9', 'local_include', 'local_include.h'], r""" +/* empty; just needs to be found */ +""") + +test.run(chdir='work9', arguments = aaa_exe) + +############################################################################## +# 10. test that an appended relative CPPPATH is working with generated files + +# this is basically test 9, but the include path is env.Append-ed and +# everything goes into sub directory "sub" +aaa_exe = os.path.join('sub', 'aaa' + _exe) + +createSConstruct(test, ['work10', 'SConstruct']) +test.write( ['work10', 'SConscript'], r""" +SConscript('sub/SConscript') +""") + +test.write( ['work10', 'sub', 'SConscript'], r""" +Import("env") +env.Append(CPPPATH=['./local_include']) +env.Program(target = 'aaa', source = 'aaa.cpp') +""") + +test.write(['work10', 'sub', 'aaa.cpp'], r""" #include "aaa.h" -void useit() { - aaa(); -} +int main() { aaa(); return 0; } +""") + +test.write(['work10', 'sub', 'aaa.h'], r""" +#include "my_qobject.h" +#include "local_include.h" +void aaa(void) Q_OBJECT; +""") + +test.write(['work10', 'sub', 'local_include', 'local_include.h'], r""" +/* empty; just needs to be found */ """) -test.run(chdir='work8', arguments = aaa_dll) +test.run(chdir='work10', arguments = aaa_exe) + +############################################################################### +# 11. test the manual QT builder calls -test.must_not_exist(test.workpath('work8', moc)) +aaa_exe = 'aaa' + _exe -test.write(['work8', 'SConscript'], """ +createSConstruct(test, ['work11', 'SConstruct']) +test.write( ['work11', 'SConscript'], r""" Import("env") -env = env.Copy(QT_AUTOBUILD_MOC_SOURCES = 1) -env.SharedLibrary(target = 'aaa', source = ['aaa.ui', 'useit.cpp']) +sources = ['aaa.cpp', 'bbb.cpp', 'ddd.cpp', 'eee.cpp', 'main.cpp'] + +# normal invocation +sources.append(env.Moc('include/aaa.h')) +env.Moc('bbb.cpp') +sources.extend(env.Uic('ui/ccc.ui')[1:]) + +# manual target specification +sources.append(env.Moc('moc-ddd.cpp', 'include/ddd.h', + QT_MOCHPREFIX='')) # Watch out ! +env.Moc('moc_eee.cpp', 'eee.cpp') +sources.extend(env.Uic(['include/uic_fff.hpp', 'fff.cpp', 'fff.moc.cpp'], + 'ui/fff.ui')[1:]) + +print map(str,sources) +env.Program(target='aaa', + source=sources, + CPPPATH=['$CPPPATH', './include'], + QT_AUTOSCAN=0) +""") + +test.write(['work11', 'aaa.cpp'], r""" +#include "aaa.h" +""") + +test.write(['work11', 'include', 'aaa.h'], r""" +#include "my_qobject.h" +void aaa(void) Q_OBJECT; +""") + +test.write(['work11', 'bbb.h'], r""" +void bbb(void); +""") + +test.write(['work11', 'bbb.cpp'], r""" +#include "my_qobject.h" +void bbb(void) Q_OBJECT +#include "bbb.moc" +""") + +test.write(['work11', 'ui', 'ccc.ui'], r""" +void ccc(void) """) -test.run(chdir='work8', arguments = aaa_dll) +test.write(['work11', 'ddd.cpp'], r""" +#include "ddd.h" +""") + +test.write(['work11', 'include', 'ddd.h'], r""" +#include "my_qobject.h" +void ddd(void) Q_OBJECT; +""") + +test.write(['work11', 'eee.h'], r""" +void eee(void); +""") + +test.write(['work11', 'eee.cpp'], r""" +#include "my_qobject.h" +void eee(void) Q_OBJECT +#include "moc_eee.cpp" +""") + +test.write(['work11', 'ui', 'fff.ui'], r""" +void fff(void) +""") -test.must_exist(test.workpath('work8', moc)) +test.write(['work11', 'main.cpp'], r""" +#include "aaa.h" +#include "bbb.h" +#include "ui/ccc.h" +#include "ddd.h" +#include "eee.h" +#include "uic_fff.hpp" +int main() { + aaa(); bbb(); ccc(); ddd(); eee(); fff(); return 0; +} +""") + +test.run(chdir='work11', arguments = aaa_exe) + +# normal invocation +test.must_exist(test.workpath('work11', 'include', 'moc_aaa.cc')) +test.must_exist(test.workpath('work11', 'bbb.moc')) +test.must_exist(test.workpath('work11', 'ui', 'ccc.h')) +test.must_exist(test.workpath('work11', 'ui', 'uic_ccc.cc')) +test.must_exist(test.workpath('work11', 'ui', 'moc_ccc.cc')) + +# manual target spec. +test.must_exist(test.workpath('work11', 'moc-ddd.cpp')) +test.must_exist(test.workpath('work11', 'moc_eee.cpp')) +test.must_exist(test.workpath('work11', 'include', 'uic_fff.hpp')) +test.must_exist(test.workpath('work11', 'fff.cpp')) +test.must_exist(test.workpath('work11', 'fff.moc.cpp')) + + +############################################################################## +# 12. test the tool warings +createSConstruct(test, ['work12', 'SConstruct']) + +test.write(['work12', 'aaa.cpp'], r""" +#include "my_qobject.h" +void aaa(void) Q_OBJECT +""") + +test.write(['work12', 'SConscript'], r""" +Import("env") +import os +env.StaticLibrary('aaa.cpp') +""") + +test.run(chdir='work12', stderr=None) +test.fail_test(not test.match_re(test.stderr(), r""" +scons: warning: Generated moc file 'aaa.moc' is not included by 'aaa.cpp' +File .+ +""")) + +os.environ['QTDIR'] = QT +test.run(chdir='work12', arguments='-n noqtdir=1') + +# We'd like to eliminate $QTDIR from the environment as follows: +# del os.environ['QTDIR'] +# But unfortunately, in at least some versions of Python, the Environment +# class doesn't implement a __delitem__() method to make the library +# call to actually remove the deleted variable from the *external* +# environment, so it only gets removed from the Python dictionary. +# Consequently, we need to just wipe out its value as follows> +os.environ['QTDIR'] = '' +test.run(chdir='work12', stderr=None, arguments='-n noqtdir=1') +test.fail_test(not test.match_re(test.stderr(), r""" +scons: warning: Could not detect qt, using empty QTDIR +File "SConstruct", line \d+, in .+ +""")) test.pass_test() diff --git a/test/QTFLAGS.py b/test/QTFLAGS.py index 7964d44..867dbfb 100644 --- a/test/QTFLAGS.py +++ b/test/QTFLAGS.py @@ -152,17 +152,21 @@ createSConstruct(test, ['SConstruct'], QT_UICDECLFLAGS='-y', QT_MOCFROMHFLAGS='-z', QT_MOCFROMCXXFLAGS='-i -w', - QT_HSUFFIX='.hpp', - QT_MOCNAMEGENERATOR=lambda x,src_suffix,env: x + '.moc.cpp', - QT_UISUFFIX='.des', - QT_UIHSUFFUX='.des.hpp', - CXXFILESUFFIX='.cpp',""") + 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.write('SConscript',""" Import("env") env.Program('mytest', ['mocFromH.cpp', 'mocFromCpp.cpp', - 'an_ui_file.des', - 'another_ui_file.des', + 'an_ui_file.myui', + 'another_ui_file.myui', 'main.cpp']) """) @@ -178,14 +182,14 @@ test.write('mocFromH.cpp', """ test.write('mocFromCpp.cpp', """ #include "my_qobject.h" void mocFromCpp() Q_OBJECT -#include "mocFromCpp.moc.cpp" +#include "mocmocFromCpp.inl" """) -test.write('an_ui_file.des', """ +test.write('an_ui_file.myui', """ void an_ui_file() """) -test.write('another_ui_file.des', """ +test.write('another_ui_file.myui', """ void another_ui_file() """) @@ -195,8 +199,8 @@ test.write('another_ui_file.desc.hpp', """ test.write('main.cpp', """ #include "mocFromH.hpp" -#include "an_ui_file.hpp" -#include "another_ui_file.hpp" +#include "uic-an_ui_file.hpp" +#include "uic-another_ui_file.hpp" void mocFromCpp(); int main() { @@ -213,14 +217,29 @@ def _existAll( test, files ): return reduce(lambda x,y: x and y, map(os.path.exists,map(test.workpath, files))) -test.fail_test(not _existAll(test, ['mocFromH.moc.cpp', - 'mocFromCpp.moc.cpp', - 'an_ui_file.cpp', - 'an_ui_file.hpp', - 'an_ui_file.moc.cpp', - 'another_ui_file.cpp', - 'another_ui_file.hpp', - 'another_ui_file.moc.cpp'])) +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'])) def _flagTest(test,fileToContentsStart): import string @@ -229,10 +248,10 @@ def _flagTest(test,fileToContentsStart): return 1 return 0 -test.fail_test(_flagTest(test, {'mocFromH.moc.cpp':'/* mymoc.py -z */', - 'mocFromCpp.moc.cpp':'/* mymoc.py -w */', - 'an_ui_file.cpp':'/* myuic.py -x */', - 'an_ui_file.hpp':'/* myuic.py -y */', - 'an_ui_file.moc.cpp':'/* mymoc.py -z */'})) +test.fail_test(_flagTest(test, {'mmmmocFromH.cxx':'/* mymoc.py -z */', + 'mocmocFromCpp.inl':'/* mymoc.py -w */', + 'an_ui_file.cxx':'/* myuic.py -x */', + 'uic-an_ui_file.hpp':'/* myuic.py -y */', + 'mmman_ui_file.cxx':'/* mymoc.py -z */'})) test.pass_test() diff --git a/test/import.py b/test/import.py index 48ae546..e7e21f1 100644 --- a/test/import.py +++ b/test/import.py @@ -119,7 +119,11 @@ error_output = { 'icl' : """ scons: warning: Intel license dir was not found. Tried using the INTEL_LICENSE_FILE environment variable (), the registry () and the default path (C:\Program Files\Common Files\Intel\Licenses). Using the default path as a last resort. File "SConstruct", line 1, in ? -""" +""", + 'qt' : """ +scons: warning: Could not detect qt, using empty QTDIR +File "SConstruct", line 1, in ? +""", } # An SConstruct for importing Tool names that have illegal characters @@ -138,6 +142,7 @@ import SCons.Tool.%s x = SCons.Tool.%s.generate """ +failures = [] for tool in tools: if tool[0] in '0123456789' or '+' in tool: test.write('SConstruct', indirect_import % (tool, tool, tool)) @@ -148,6 +153,8 @@ for tool in tools: if stderr != '' and stderr != error_output.get(tool, ''): print "Failed importing '%s', stderr:" % tool print stderr - test.fail_test(1) + failures.append[tool] + +test.fail_test(len(failures)) test.pass_test() |