From 6c87a951609ea30f775f671f1c1774744690d98e Mon Sep 17 00:00:00 2001 From: stevenknight Date: Sun, 25 Jan 2004 01:45:35 +0000 Subject: [PATCH] Have the Qt Builder(s) use flags from the environment used to specify the target, not the environment that first had the Builder(s) attached. (Christoph Wiedemann) git-svn-id: http://scons.tigris.org/svn/scons/trunk@884 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 6 +++ src/engine/SCons/Tool/qt.py | 15 ++++---- test/QT.py | 73 ++++++++++++++++++++++++++++++------- 3 files changed, 74 insertions(+), 20 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 3e0feaa4..f03e7bd2 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -162,6 +162,12 @@ RELEASE 0.95 - XXX - Evaluate $MSVSPROJECTSUFFIX and $MSVSSOLUTIONSUFFIX when the Builder is invoked, not when the tool is initialized. + From Christoph Wiedemann: + + - When compiling Qt, make sure the moc_*.cc files are compiled using + the flags from the environment used to specify the target, not + the environment that first has the Qt Builders attached. + RELEASE 0.94 - Fri, 07 Nov 2003 05:29:48 -0600 diff --git a/src/engine/SCons/Tool/qt.py b/src/engine/SCons/Tool/qt.py index ffdff18c..4be7a654 100644 --- a/src/engine/SCons/Tool/qt.py +++ b/src/engine/SCons/Tool/qt.py @@ -53,8 +53,8 @@ class _Automoc: StaticLibraries. """ - def __init__(self, objBuilder,uicDeclBuild,mocFromHBld,mocFromCppBld): - self.objBuilder = objBuilder + def __init__(self, objBuilderName,uicDeclBuild,mocFromHBld,mocFromCppBld): + self.objBuilderName = objBuilderName self.uicDeclBld = uicDeclBuild self.mocFromHBld = mocFromHBld self.mocFromCppBld = mocFromCppBld @@ -108,9 +108,10 @@ class _Automoc: src_ext = SCons.Util.splitext(str(h))[1] moc_cpp = SCons.Node.FS.default_fs.File(os.path.join(dir, env['QT_MOCNAMEGENERATOR'](base, src_ext, env))) - moc_o = self.objBuilder(source=moc_cpp) + objBuilder = getattr(env, self.objBuilderName) + moc_o = objBuilder(source=moc_cpp) out_sources.append(moc_o) - self.objBuilder(moc_o, moc_cpp) + objBuilder(moc_o, moc_cpp) self.mocFromHBld(env, moc_cpp, h) moc_cpp.target_scanner = SCons.Defaults.CScan if cpp and q_object_search.search(cpp.get_contents()): @@ -202,11 +203,11 @@ def generate(env): # We can't refer to the builders directly, we have to fetch them # as Environment attributes because that sets them up to be called # correctly later by our emitter. - env['PROGEMITTER'] = _Automoc(env.StaticObject, + env['PROGEMITTER'] = _Automoc('StaticObject', uicDeclBld,mocFromHBld,mocFromCppBld) - env['SHLIBEMITTER'] = _Automoc(env.SharedObject, + env['SHLIBEMITTER'] = _Automoc('SharedObject', uicDeclBld,mocFromHBld,mocFromCppBld) - env['LIBEMITTER'] = _Automoc(env.StaticObject, + env['LIBEMITTER'] = _Automoc('StaticObject', uicDeclBld,mocFromHBld,mocFromCppBld) # Of course, we need to link against the qt libraries env.Append(CPPPATH=os.path.join('$QTDIR', 'include')) diff --git a/test/QT.py b/test/QT.py index 8b255532..0a2505e2 100644 --- a/test/QT.py +++ b/test/QT.py @@ -29,8 +29,10 @@ Testing the 'qt' tool, i.e. support for .ui files and automatic generation of qt's moc files. """ -import TestSCons import os.path +import string + +import TestSCons python = TestSCons.python _exe = TestSCons._exe @@ -123,7 +125,8 @@ QT_LIB = 'myqt' QT_MOC = '%s %s' % (python, test.workpath('qt','bin','mymoc.py')) QT_UIC = '%s %s' % (python, test.workpath('qt','bin','myuic.py')) -# 3 test cases with 3 different operation modes +############################################################################## +# 4 test cases with 4 different operation modes def createSConstruct(test,place): test.write(place, """ @@ -145,8 +148,9 @@ Export("env") SConscript( sconscript ) """ % (QT, QT_LIB, QT_MOC, QT_UIC)) -test.subdir( 'work1', 'work2', 'work3', 'work4' ) +test.subdir( 'work1', 'work2', 'work3', 'work4', 'work5' ) +############################################################################## # 1. create a moc file from a header file. aaa_exe = 'aaa' + _exe @@ -189,6 +193,7 @@ test.run(chdir='work1', test.fail_test( not os.path.exists(test.workpath('work1', 'build', moc)) ) +############################################################################## # 2. create .cpp, .h, moc_....cpp from .ui file aaa_dll = dll_ + 'aaa' + _dll @@ -241,6 +246,7 @@ 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))) +############################################################################## # 3. create a moc file from a cpp file lib_aaa = lib_ + 'aaa' + _lib @@ -288,6 +294,47 @@ test.run(chdir='work3', test.fail_test(not os.path.exists(test.workpath('work3', 'build', moc))) +############################################################################## +# 4. Test with a copied environment. + +createSConstruct(test, ['work4', 'SConstruct']) +test.write(['work4', 'SConscript'], """\ +Import("env") +env.Append(CPPDEFINES = ['FOOBAZ']) + +copy = env.Copy() +copy.Append(CPPDEFINES = ['MYLIB_IMPL']) + +copy.SharedLibrary( + target = 'MyLib', + source = ['MyFile.cpp','MyForm.ui'] +) +""") + +test.write(['work4', 'MyFile.h'], r""" +void aaa(void); +""") + +test.write(['work4', 'MyFile.cpp'], r""" +#include "MyFile.h" +void useit() { + aaa(); +} +""") + +test.write(['work4', 'MyForm.ui'], r""" +void aaa(void) +""") + +test.run(chdir='work4') +moc_MyForm = filter(lambda x: string.find(x, 'moc_MyForm') != -1, + string.split(test.stdout(), '\n')) +MYLIB_IMPL = filter(lambda x: string.find(x, 'MYLIB_IMPL') != -1, moc_MyForm) +if not MYLIB_IMPL: + print "Did not find MYLIB_IMPL on moc_MyForm compilation line:" + print test.stdout() + test.fail_test() + # look if qt is installed, and try out all builders @@ -296,7 +343,7 @@ if os.environ.get('QTDIR', None): QTDIR=os.environ['QTDIR'] - test.write( ['work4', 'SConstruct'],""" + test.write( ['work5', 'SConstruct'],""" import os dummy_env = Environment() ENV = dummy_env['ENV'] @@ -332,11 +379,11 @@ env.Program('test_realqt', ['mocFromCpp.cpp', 'main.cpp']) """) - test.write( ['work4', 'mocFromCpp.h'],""" + test.write( ['work5', 'mocFromCpp.h'],""" void mocFromCpp(); """) - test.write( ['work4', 'mocFromCpp.cpp'],""" + test.write( ['work5', 'mocFromCpp.cpp'],""" #include #include "mocFromCpp.h" class MyClass1 : public QObject { @@ -352,7 +399,7 @@ void mocFromCpp() { #include "moc_mocFromCpp.cpp" """) - test.write( ['work4', 'mocFromH.h'],""" + test.write( ['work5', 'mocFromH.h'],""" #include class MyClass2 : public QObject { Q_OBJECT; @@ -364,7 +411,7 @@ class MyClass2 : public QObject { void mocFromH(); """) - test.write( ['work4', 'mocFromH.cpp'],""" + test.write( ['work5', 'mocFromH.cpp'],""" #include "mocFromH.h" MyClass2::MyClass2() : QObject() {} @@ -374,7 +421,7 @@ void mocFromH() { } """) - test.write( ['work4', 'anUiFile.ui'],""" + test.write( ['work5', 'anUiFile.ui'],""" MyWidget @@ -390,7 +437,7 @@ void mocFromH() { """) - test.write( ['work4', 'main.cpp'], """ + test.write( ['work5', 'main.cpp'], """ #include "mocFromCpp.h" #include "mocFromH.h" #include "anUiFile.h" @@ -401,13 +448,13 @@ int main() { } """) - test.run(chdir='work4', arguments="test_realqt" + _exe) + test.run(chdir='work5', arguments="test_realqt" + _exe) QTDIR=os.environ['QTDIR'] del os.environ['QTDIR'] - test.run(chdir='work4', arguments="-c test_realqt" + _exe) - test.run(chdir='work4', arguments="PATH=%s/bin test_realqt%s"%(QTDIR,_exe)) + test.run(chdir='work5', arguments="-c test_realqt" + _exe) + test.run(chdir='work5', arguments="PATH=%s/bin test_realqt%s"%(QTDIR,_exe)) else: print "Could not find QT, skipping test(s)." -- 2.26.2