5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 Testing the configuration mechanisms of the 'qt' tool.
32 _python_
= TestSCons
._python
_
35 test
= TestSCons
.TestSCons()
37 test
.Qt_dummy_installation()
38 test
.subdir('work1', 'work2')
41 chdir
=test
.workpath('qt', 'lib'),
42 arguments
="--warn=no-tool-qt-deprecated .",
43 stderr
=TestSCons
.noisy_ar
,
44 match
=TestSCons
.match_re_dotall
,
47 QT
= test
.workpath('qt')
49 QT_MOC
= '%s %s' % (_python_
, test
.workpath('qt', 'bin', 'mymoc.py'))
50 QT_UIC
= '%s %s' % (_python_
, test
.workpath('qt', 'bin', 'myuic.py'))
52 def createSConstruct(test
, place
, overrides
):
53 test
.write(place
, """\
55 tools=['default','qt'],
60 %s # last because 'overrides' may add comma
62 if ARGUMENTS.get('variant_dir', 0):
63 if ARGUMENTS.get('chdir', 0):
67 VariantDir('build', '.', duplicate=1)
68 sconscript = Dir('build').File('SConscript')
70 sconscript = File('SConscript')
72 SConscript(sconscript)
73 """ % (QT
, QT_LIB
, QT_MOC
, QT_UIC
, overrides
))
76 createSConstruct(test
, ['work1', 'SConstruct'],
77 """QT_UICIMPLFLAGS='-x',
79 QT_MOCFROMHFLAGS='-z',
80 QT_MOCFROMCXXFLAGS='-i -w',
81 QT_UICDECLPREFIX='uic-',
82 QT_UICDECLSUFFIX='.hpp',
84 QT_UICIMPLSUFFIX='.cxx',
87 QT_MOCCXXPREFIX='moc',
88 QT_MOCCXXSUFFIX='.inl',
89 QT_UISUFFIX='.myui',""")
90 test
.write(['work1', 'SConscript'],"""
92 env.Program('mytest', ['mocFromH.cpp',
95 'another_ui_file.myui',
99 test
.write(['work1', 'mocFromH.hpp'], """
100 #include "my_qobject.h"
101 void mocFromH() Q_OBJECT
104 test
.write(['work1', 'mocFromH.cpp'], """
105 #include "mocFromH.hpp"
108 test
.write(['work1', 'mocFromCpp.cpp'], """
109 #include "my_qobject.h"
110 void mocFromCpp() Q_OBJECT
111 #include "mocmocFromCpp.inl"
114 test
.write(['work1', 'an_ui_file.myui'], """
118 test
.write(['work1', 'another_ui_file.myui'], """
119 void another_ui_file()
122 test
.write(['work1', 'another_ui_file.desc.hpp'], """
123 /* just a dependency checker */
126 test
.write(['work1', 'main.cpp'], """
127 #include "mocFromH.hpp"
128 #include "uic-an_ui_file.hpp"
129 #include "uic-another_ui_file.hpp"
140 test
.run(chdir
='work1', arguments
="--warn=no-tool-qt-deprecated mytest" + _exe
)
143 ['work1', 'mmmmocFromH.cxx'],
144 ['work1', 'mocmocFromCpp.inl'],
145 ['work1', 'an_ui_file.cxx'],
146 ['work1', 'uic-an_ui_file.hpp'],
147 ['work1', 'mmman_ui_file.cxx'],
148 ['work1', 'another_ui_file.cxx'],
149 ['work1', 'uic-another_ui_file.hpp'],
150 ['work1', 'mmmanother_ui_file.cxx'],
153 def _flagTest(test
,fileToContentsStart
):
154 for f
,c
in fileToContentsStart
.items():
155 if test
.read(test
.workpath('work1', f
), mode
='r').find(c
) != 0:
163 'mmmmocFromH.cxx': '/* mymoc.py -z */',
164 'mocmocFromCpp.inl': '/* mymoc.py -w */',
165 'an_ui_file.cxx': '/* myuic.py -x */',
166 'uic-an_ui_file.hpp': '/* myuic.py -y */',
167 'mmman_ui_file.cxx': '/* mymoc.py -z */',
172 test
.write(['work2', 'SConstruct'], """
178 QT_BINPATH='$QTDIR/bin64',
179 QT_LIBPATH='$QTDIR/lib64',
180 QT_CPPPATH='$QTDIR/h64',
183 cpppath = env1.subst('$CPPPATH')
184 if os.path.normpath(cpppath) != os.path.join(r'%(QTDIR)s', 'h64'):
187 libpath = env1.subst('$LIBPATH')
188 if os.path.normpath(libpath) != os.path.join(r'%(QTDIR)s', 'lib64'):
191 qt_moc = env1.subst('$QT_MOC')
192 if os.path.normpath(qt_moc) != os.path.join(r'%(QTDIR)s', 'bin64', 'moc'):
197 tools=['default', 'qt'], QTDIR=None, QT_LIB=None, QT_CPPPATH=None, QT_LIBPATH=None
200 env2.Program('main.cpp')
203 test
.write(['work2', 'main.cpp'], """
204 int main(void) { return 0; }
207 # Ignore stderr, because if Qt is not installed,
208 # there may be a warning about an empty QTDIR on stderr.
209 test
.run(arguments
="--warn=no-tool-qt-deprecated", chdir
='work2', stderr
=None)
211 test
.must_exist(['work2', 'main' + _exe
])
217 # indent-tabs-mode:nil
219 # vim: set expandtab tabstop=4 shiftwidth=4: