fix typo
[scons.git] / test / QT / QTFLAGS.py
blobc759c2a4ad8bea1906fec9b8db566b48bee1d51e
1 #!/usr/bin/env python
3 # MIT License
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.
26 """
27 Testing the configuration mechanisms of the 'qt' tool.
28 """
30 import TestSCons
32 _python_ = TestSCons._python_
33 _exe = TestSCons._exe
35 test = TestSCons.TestSCons()
37 test.Qt_dummy_installation()
38 test.subdir('work1', 'work2')
40 test.run(
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')
48 QT_LIB = 'myqt'
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, """\
54 env = Environment(
55 tools=['default','qt'],
56 QTDIR = r'%s',
57 QT_LIB = r'%s',
58 QT_MOC = r'%s',
59 QT_UIC = r'%s',
60 %s # last because 'overrides' may add comma
62 if ARGUMENTS.get('variant_dir', 0):
63 if ARGUMENTS.get('chdir', 0):
64 SConscriptChdir(1)
65 else:
66 SConscriptChdir(0)
67 VariantDir('build', '.', duplicate=1)
68 sconscript = Dir('build').File('SConscript')
69 else:
70 sconscript = File('SConscript')
71 Export("env")
72 SConscript(sconscript)
73 """ % (QT, QT_LIB, QT_MOC, QT_UIC, overrides))
76 createSConstruct(test, ['work1', 'SConstruct'],
77 """QT_UICIMPLFLAGS='-x',
78 QT_UICDECLFLAGS='-y',
79 QT_MOCFROMHFLAGS='-z',
80 QT_MOCFROMCXXFLAGS='-i -w',
81 QT_UICDECLPREFIX='uic-',
82 QT_UICDECLSUFFIX='.hpp',
83 QT_UICIMPLPREFIX='',
84 QT_UICIMPLSUFFIX='.cxx',
85 QT_MOCHPREFIX='mmm',
86 QT_MOCHSUFFIX='.cxx',
87 QT_MOCCXXPREFIX='moc',
88 QT_MOCCXXSUFFIX='.inl',
89 QT_UISUFFIX='.myui',""")
90 test.write(['work1', 'SConscript'],"""
91 Import("env")
92 env.Program('mytest', ['mocFromH.cpp',
93 'mocFromCpp.cpp',
94 'an_ui_file.myui',
95 'another_ui_file.myui',
96 'main.cpp'])
97 """)
99 test.write(['work1', 'mocFromH.hpp'], """
100 #include "my_qobject.h"
101 void mocFromH() Q_OBJECT
102 """)
104 test.write(['work1', 'mocFromH.cpp'], """
105 #include "mocFromH.hpp"
106 """)
108 test.write(['work1', 'mocFromCpp.cpp'], """
109 #include "my_qobject.h"
110 void mocFromCpp() Q_OBJECT
111 #include "mocmocFromCpp.inl"
112 """)
114 test.write(['work1', 'an_ui_file.myui'], """
115 void an_ui_file()
116 """)
118 test.write(['work1', 'another_ui_file.myui'], """
119 void another_ui_file()
120 """)
122 test.write(['work1', 'another_ui_file.desc.hpp'], """
123 /* just a dependency checker */
124 """)
126 test.write(['work1', 'main.cpp'], """
127 #include "mocFromH.hpp"
128 #include "uic-an_ui_file.hpp"
129 #include "uic-another_ui_file.hpp"
130 void mocFromCpp();
132 int main(void) {
133 mocFromH();
134 mocFromCpp();
135 an_ui_file();
136 another_ui_file();
138 """)
140 test.run(chdir='work1', arguments="--warn=no-tool-qt-deprecated mytest" + _exe)
142 test.must_exist(
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:
156 return 1
157 return 0
159 test.fail_test(
160 _flagTest(
161 test,
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'], """
173 import os.path
175 env1 = Environment(
176 tools=['qt'],
177 QTDIR=r'%(QTDIR)s',
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'):
185 print(cpppath)
186 Exit(1)
187 libpath = env1.subst('$LIBPATH')
188 if os.path.normpath(libpath) != os.path.join(r'%(QTDIR)s', 'lib64'):
189 print(libpath)
190 Exit(2)
191 qt_moc = env1.subst('$QT_MOC')
192 if os.path.normpath(qt_moc) != os.path.join(r'%(QTDIR)s', 'bin64', 'moc'):
193 print(qt_moc)
194 Exit(3)
196 env2 = Environment(
197 tools=['default', 'qt'], QTDIR=None, QT_LIB=None, QT_CPPPATH=None, QT_LIBPATH=None
200 env2.Program('main.cpp')
201 """ % {'QTDIR':QT})
203 test.write(['work2', 'main.cpp'], """
204 int main(void) { return 0; }
205 """)
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])
213 test.pass_test()
215 # Local Variables:
216 # tab-width:4
217 # indent-tabs-mode:nil
218 # End:
219 # vim: set expandtab tabstop=4 shiftwidth=4: