From ee21efd9c35efe94a6b60b80be29bd2eedae991b Mon Sep 17 00:00:00 2001 From: stevenknight Date: Fri, 8 Oct 2004 01:44:16 +0000 Subject: [PATCH] Have the Qt Builder make uic-built files dependent on the .ui.h file, if it exists. (Christoph Wiedemann) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1121 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 3 ++ src/engine/SCons/Tool/qt.py | 25 +++++++++- test/QT.py | 98 ++++++++++++++++++++++++------------- 3 files changed, 90 insertions(+), 36 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 1a97d15a..80c14d12 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -242,6 +242,9 @@ RELEASE 0.97 - XXX - Additional significant internal cleanups in the Configure() subsystem and its tests. + - Have the Qt Builder make uic-generated files dependent on the .ui.h + file, if one exists. + RELEASE 0.96.1 - XXX diff --git a/src/engine/SCons/Tool/qt.py b/src/engine/SCons/Tool/qt.py index c6237d36..9bb04380 100644 --- a/src/engine/SCons/Tool/qt.py +++ b/src/engine/SCons/Tool/qt.py @@ -38,6 +38,7 @@ import os.path import re import SCons.Defaults +import SCons.Scanner import SCons.Tool import SCons.Util @@ -218,6 +219,27 @@ def uicEmitter(target, source, env): env.subst('$QT_MOCHSUFFIX'))) return target, source +def uicScannerFunc(node, env, path): + #print "uicScannerFunc" + dir = node.dir + includes = re.findall("(.*?)", node.get_contents()) + res = [] + for incFile in includes: + incNode = dir.File(incFile) + if incNode.rexists(): + #print "uicdep: ", incNode + res.append(dir.File(incFile)) + else: + #print "uicdep: ", incNode, "not found" + pass + return res + +uicScanner = SCons.Scanner.Scanner(uicScannerFunc, + name = "UicScanner", + node_class = SCons.Node.FS.File, + node_factory = SCons.Node.FS.File, + recursive = 0) + def generate(env): """Add Builders and construction variables for qt to an Environment.""" CLVar = SCons.Util.CLVar @@ -276,7 +298,8 @@ def generate(env): emitter=uicEmitter, src_suffix='$QT_UISUFFIX', suffix='$QT_UICDECLSUFFIX', - prefix='$QT_UICDECLPREFIX') + prefix='$QT_UICDECLPREFIX', + source_scanner=uicScanner) mocBld = Builder(action={}, prefix={}, suffix={}) for h in header_extensions: mocBld.add_action(h, '$QT_MOCFROMHCOM') diff --git a/test/QT.py b/test/QT.py index 51021a53..680784f5 100644 --- a/test/QT.py +++ b/test/QT.py @@ -73,8 +73,9 @@ sys.exit(0) """ ) test.write(['qt', 'bin', 'myuic.py'], """ -import sys import os.path +import re +import sys import string output_arg = 0 impl_arg = 0 @@ -98,10 +99,11 @@ for arg in sys.argv[1:]: 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') + includes = re.findall('(.*?)', source.read()) + for incFile in includes: + # this is valid for ui.h files, at least + if os.path.exists(incFile): + output.write('#include "' + incFile + '"\\n') else: output.write( '#include "my_qobject.h"\\n' + source.read() + " Q_OBJECT \\n" ) output.close() @@ -271,21 +273,22 @@ test.not_up_to_date(chdir='work2', options = '-n', arguments = moc) test.not_up_to_date(chdir='work2', options = '-n', arguments = cpp) test.not_up_to_date(chdir='work2', options = '-n', arguments = h) test.run(chdir='work2', arguments = aaa_dll) -test.write(['work2', 'aaa.ui.h'], r""" -/* test dependency to .ui.h */ -""") test.write(['work2', 'aaa.ui'], r""" void aaa(void) -// ui.h +//aaa.ui.h +""") +test.run(chdir='work2', arguments = aaa_dll) # test that non-existant ui.h files are ignored (as uic does) +test.write(['work2', 'aaa.ui.h'], r""" +/* test dependency to .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) +test.not_up_to_date(chdir='work2', options = '-n', arguments = cpp) +test.not_up_to_date(chdir='work2', options = '-n', arguments = h) +test.not_up_to_date(chdir='work2', options = '-n', arguments = moc) # clean up test.run(chdir='work2', arguments = '-c ' + aaa_dll) @@ -298,6 +301,9 @@ test.fail_test(not os.path.exists(test.workpath('work2','build',moc)) or os.path.exists(test.workpath('work2', moc)) or os.path.exists(test.workpath('work2', cpp)) or os.path.exists(test.workpath('work2', h))) +cppContents = test.read(test.workpath('work2', 'build', cpp)) +test.fail_test(string.find(cppContents, '#include "aaa.ui.h"') == -1) + test.run(chdir='work2', arguments = "build_dir=1 chdir=1 " + test.workpath('work2', 'build', aaa_dll) ) @@ -319,7 +325,6 @@ test.must_not_exist(['work2', moc], ['work2', cpp], ['work2', h]) - ############################################################################## # 3. create a moc file from a cpp file @@ -522,16 +527,16 @@ env = Environment(tools=['default','qt'], CXXFILESUFFIX=".cpp") conf = env.Configure() -if not conf.CheckLib(env.subst("$QT_LIB")): +if not conf.CheckLib(env.subst("$QT_LIB"), autoadd=0): conf.env['QT_LIB'] = 'qt-mt' - if not conf.CheckLib(env.subst("$QT_LIB")): + if not conf.CheckLib(env.subst("$QT_LIB"), autoadd=0): Exit(0) env = conf.Finish() - -env.Program('test_realqt', ['mocFromCpp.cpp', - 'mocFromH.cpp', - 'anUiFile.ui', - 'main.cpp']) +BuildDir('bld', '.') +env.Program('bld/test_realqt', ['bld/mocFromCpp.cpp', + 'bld/mocFromH.cpp', + 'bld/anUiFile.ui', + 'bld/main.cpp']) """) test.write( ['work7', 'mocFromCpp.h'],""" @@ -588,42 +593,67 @@ void mocFromH() { MyWidget + + anUiFile.ui.h + + + testSlot() + +""") + test.write( ['work7', 'anUiFile.ui.h'], r""" +#include +#if QT_VERSION >= 0x030100 +void MyWidget::testSlot() +{ + printf("Hello World\n"); +} +#endif """) - test.write( ['work7', 'main.cpp'], """ + test.write( ['work7', 'main.cpp'], r""" +#include #include "mocFromCpp.h" #include "mocFromH.h" #include "anUiFile.h" -int main() { +#include + +int main(int argc, char **argv) { + QApplication app(argc, argv); mocFromCpp(); mocFromH(); - MyWidget mywidget(); + MyWidget mywidget; +#if QT_VERSION >= 0x030100 + mywidget.testSlot(); +#else + printf("Hello World\n"); +#endif + return 0; } """) - test.run(chdir='work7', arguments="test_realqt" + _exe) + test.run(chdir='work7', arguments="bld/test_realqt" + _exe) + test.run(program=test.workpath("work7", "bld", "test_realqt"), + stdout="Hello World\n") QTDIR=os.environ['QTDIR'] del os.environ['QTDIR'] PATH=os.environ['PATH'] os.environ['PATH']='.' - test.run(chdir='work7', stderr=None, arguments="-c test_realqt" + _exe) + test.run(chdir='work7', stderr=None, arguments="-c bld/test_realqt" + _exe) test.fail_test(not test.match_re_dotall(test.stderr(), r""".* scons: warning: Could not detect qt, using empty QTDIR -File "[^\"]*", line \d+, in .+ -""")) +""" + TestSCons.file_expr)) os.environ['PATH'] = PATH test.run(chdir='work7', stderr=None, - arguments="PATH=%s%sbin test_realqt%s"%(QTDIR,os.sep,_exe)) - test.fail_test(not test.match_re(test.stderr(), r""" + arguments="PATH=%s%sbin bld%stest_realqt%s"%(QTDIR,os.sep,os.sep,_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 "[^\"]*", line \d+, in .+ -""" % (re.escape(QTDIR)))) +""" + TestSCons.file_expr) % re.escape(QTDIR))) else: @@ -875,8 +905,7 @@ test.run(chdir='work12', stderr=None) match12 = r""" scons: warning: Generated moc file 'aaa.moc' is not included by 'aaa.cpp' -File .+ -""" +""" + TestSCons.file_expr # In case 'ar' gives a warning about creating a library. test.fail_test(not test.match_re(test.stderr(), match12) and \ @@ -896,7 +925,6 @@ 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 "[^\"]*", line \d+, in .+ -""")) +""" + TestSCons.file_expr)) test.pass_test() -- 2.26.2