merge current upstream
[scons.git] / test / QT / QTFLAGS.py
blobaa142f5165f2d73ac938352c1e081552a676aaf7
1 #!/usr/bin/env python
3 # __COPYRIGHT__
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Testing the configuration mechanisms of the 'qt' tool.
29 """
31 import TestSCons
33 _python_ = TestSCons._python_
34 _exe = TestSCons._exe
36 test = TestSCons.TestSCons()
38 test.Qt_dummy_installation()
39 test.subdir('work1', 'work2')
41 test.run(
42 chdir=test.workpath('qt', 'lib'),
43 arguments='.',
44 stderr=TestSCons.noisy_ar,
45 match=TestSCons.match_re_dotall,
48 QT = test.workpath('qt')
49 QT_LIB = 'myqt'
50 QT_MOC = '%s %s' % (_python_, test.workpath('qt', 'bin', 'mymoc.py'))
51 QT_UIC = '%s %s' % (_python_, test.workpath('qt', 'bin', 'myuic.py'))
53 def createSConstruct(test, place, overrides):
54 test.write(place, """\
55 env = Environment(
56 tools=['default','qt'],
57 QTDIR = r'%s',
58 QT_LIB = r'%s',
59 QT_MOC = r'%s',
60 QT_UIC = r'%s',
61 %s # last because 'overrides' may add comma
63 if ARGUMENTS.get('variant_dir', 0):
64 if ARGUMENTS.get('chdir', 0):
65 SConscriptChdir(1)
66 else:
67 SConscriptChdir(0)
68 VariantDir('build', '.', duplicate=1)
69 sconscript = Dir('build').File('SConscript')
70 else:
71 sconscript = File('SConscript')
72 Export("env")
73 SConscript(sconscript)
74 """ % (QT, QT_LIB, QT_MOC, QT_UIC, overrides))
77 createSConstruct(test, ['work1', 'SConstruct'],
78 """QT_UICIMPLFLAGS='-x',
79 QT_UICDECLFLAGS='-y',
80 QT_MOCFROMHFLAGS='-z',
81 QT_MOCFROMCXXFLAGS='-i -w',
82 QT_UICDECLPREFIX='uic-',
83 QT_UICDECLSUFFIX='.hpp',
84 QT_UICIMPLPREFIX='',
85 QT_UICIMPLSUFFIX='.cxx',
86 QT_MOCHPREFIX='mmm',
87 QT_MOCHSUFFIX='.cxx',
88 QT_MOCCXXPREFIX='moc',
89 QT_MOCCXXSUFFIX='.inl',
90 QT_UISUFFIX='.myui',""")
91 test.write(['work1', 'SConscript'],"""
92 Import("env")
93 env.Program('mytest', ['mocFromH.cpp',
94 'mocFromCpp.cpp',
95 'an_ui_file.myui',
96 'another_ui_file.myui',
97 'main.cpp'])
98 """)
100 test.write(['work1', 'mocFromH.hpp'], """
101 #include "my_qobject.h"
102 void mocFromH() Q_OBJECT
103 """)
105 test.write(['work1', 'mocFromH.cpp'], """
106 #include "mocFromH.hpp"
107 """)
109 test.write(['work1', 'mocFromCpp.cpp'], """
110 #include "my_qobject.h"
111 void mocFromCpp() Q_OBJECT
112 #include "mocmocFromCpp.inl"
113 """)
115 test.write(['work1', 'an_ui_file.myui'], """
116 void an_ui_file()
117 """)
119 test.write(['work1', 'another_ui_file.myui'], """
120 void another_ui_file()
121 """)
123 test.write(['work1', 'another_ui_file.desc.hpp'], """
124 /* just a dependency checker */
125 """)
127 test.write(['work1', 'main.cpp'], """
128 #include "mocFromH.hpp"
129 #include "uic-an_ui_file.hpp"
130 #include "uic-another_ui_file.hpp"
131 void mocFromCpp();
133 int main(void) {
134 mocFromH();
135 mocFromCpp();
136 an_ui_file();
137 another_ui_file();
139 """)
141 test.run(chdir = 'work1', arguments = "mytest" + _exe)
143 test.must_exist(['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'])
152 def _flagTest(test,fileToContentsStart):
153 for f,c in fileToContentsStart.items():
154 if test.read(test.workpath('work1', f), mode='r').find(c) != 0:
155 return 1
156 return 0
158 test.fail_test(_flagTest(test, {'mmmmocFromH.cxx':'/* mymoc.py -z */',
159 'mocmocFromCpp.inl':'/* mymoc.py -w */',
160 'an_ui_file.cxx':'/* myuic.py -x */',
161 'uic-an_ui_file.hpp':'/* myuic.py -y */',
162 'mmman_ui_file.cxx':'/* mymoc.py -z */'}))
164 test.write(['work2', 'SConstruct'], """
165 import os.path
166 env1 = Environment(tools=['qt'],
167 QTDIR = r'%(QTDIR)s',
168 QT_BINPATH='$QTDIR/bin64',
169 QT_LIBPATH='$QTDIR/lib64',
170 QT_CPPPATH='$QTDIR/h64')
172 cpppath = env1.subst('$CPPPATH')
173 if os.path.normpath(cpppath) != os.path.join(r'%(QTDIR)s', 'h64'):
174 print(cpppath)
175 Exit(1)
176 libpath = env1.subst('$LIBPATH')
177 if os.path.normpath(libpath) != os.path.join(r'%(QTDIR)s', 'lib64'):
178 print(libpath)
179 Exit(2)
180 qt_moc = env1.subst('$QT_MOC')
181 if os.path.normpath(qt_moc) != os.path.join(r'%(QTDIR)s', 'bin64', 'moc'):
182 print(qt_moc)
183 Exit(3)
185 env2 = Environment(tools=['default', 'qt'],
186 QTDIR = None,
187 QT_LIB = None,
188 QT_CPPPATH = None,
189 QT_LIBPATH = None)
191 env2.Program('main.cpp')
192 """ % {'QTDIR':QT})
194 test.write(['work2', 'main.cpp'], """
195 int main(void) { return 0; }
196 """)
198 # Ignore stderr, because if Qt is not installed,
199 # there may be a warning about an empty QTDIR on stderr.
200 test.run(chdir='work2', stderr=None)
202 test.must_exist(['work2', 'main' + _exe])
204 test.pass_test()
206 # Local Variables:
207 # tab-width:4
208 # indent-tabs-mode:nil
209 # End:
210 # vim: set expandtab tabstop=4 shiftwidth=4: