Move 2.0 changes collected in branches/pending back to trunk for further
[scons.git] / test / QT / QTFLAGS.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Testing the configuration mechanisms of the 'qt' tool.
29 """
30
31 import TestSCons
32
33 _python_ = TestSCons._python_
34 _exe = TestSCons._exe
35
36 test = TestSCons.TestSCons()
37
38 test.subdir( 'qt', ['qt', 'bin'], ['qt', 'include'], ['qt', 'lib'],
39              'work1', 'work2')
40
41 test.Qt_dummy_installation()
42
43 test.run(chdir=test.workpath('qt','lib'), arguments = '.',
44          stderr=TestSCons.noisy_ar,
45          match=TestSCons.match_re_dotall)
46
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'))
51
52 def createSConstruct(test,place,overrides):
53     test.write(place, """
54 env = Environment(QTDIR = r'%s',
55                   QT_LIB = r'%s',
56                   QT_MOC = r'%s',
57                   QT_UIC = r'%s',
58                   %s
59                   tools=['default','qt'])
60 if ARGUMENTS.get('variant_dir', 0):
61     if ARGUMENTS.get('chdir', 0):
62         SConscriptChdir(1)
63     else:
64         SConscriptChdir(0)
65     VariantDir('build', '.', duplicate=1)
66     sconscript = Dir('build').File('SConscript')
67 else:
68     sconscript = File('SConscript')
69 Export("env")
70 SConscript( sconscript )
71 """ % (QT, QT_LIB, QT_MOC, QT_UIC, overrides))
72
73
74 createSConstruct(test, ['work1', 'SConstruct'],
75                  """QT_UICIMPLFLAGS='-x',
76                     QT_UICDECLFLAGS='-y',
77                     QT_MOCFROMHFLAGS='-z',
78                     QT_MOCFROMCXXFLAGS='-i -w',
79                     QT_UICDECLPREFIX='uic-',
80                     QT_UICDECLSUFFIX='.hpp',
81                     QT_UICIMPLPREFIX='',
82                     QT_UICIMPLSUFFIX='.cxx',
83                     QT_MOCHPREFIX='mmm',
84                     QT_MOCHSUFFIX='.cxx',
85                     QT_MOCCXXPREFIX='moc',
86                     QT_MOCCXXSUFFIX='.inl',
87                     QT_UISUFFIX='.myui',""")
88 test.write(['work1', 'SConscript'],"""
89 Import("env")
90 env.Program('mytest', ['mocFromH.cpp',
91                        'mocFromCpp.cpp',
92                        'an_ui_file.myui',
93                        'another_ui_file.myui',
94                        'main.cpp'])
95 """)
96
97 test.write(['work1', 'mocFromH.hpp'], """
98 #include "my_qobject.h"
99 void mocFromH() Q_OBJECT
100 """)
101
102 test.write(['work1', 'mocFromH.cpp'], """
103 #include "mocFromH.hpp"
104 """)
105
106 test.write(['work1', 'mocFromCpp.cpp'], """
107 #include "my_qobject.h"
108 void mocFromCpp() Q_OBJECT
109 #include "mocmocFromCpp.inl"
110 """)
111
112 test.write(['work1', 'an_ui_file.myui'], """
113 void an_ui_file()
114 """)
115
116 test.write(['work1', 'another_ui_file.myui'], """
117 void another_ui_file()
118 """)
119
120 test.write(['work1', 'another_ui_file.desc.hpp'], """
121 /* just a dependency checker */
122 """)
123
124 test.write(['work1', 'main.cpp'], """
125 #include "mocFromH.hpp"
126 #include "uic-an_ui_file.hpp"
127 #include "uic-another_ui_file.hpp"
128 void mocFromCpp();
129
130 int main() {
131   mocFromH();
132   mocFromCpp();
133   an_ui_file();
134   another_ui_file();
135 }
136 """)
137
138 test.run(chdir = 'work1', arguments = "mytest" + _exe)
139                        
140 test.must_exist(['work1', 'mmmmocFromH.cxx'],
141                 ['work1', 'mocmocFromCpp.inl'],
142                 ['work1', 'an_ui_file.cxx'],
143                 ['work1', 'uic-an_ui_file.hpp'],
144                 ['work1', 'mmman_ui_file.cxx'],
145                 ['work1', 'another_ui_file.cxx'],
146                 ['work1', 'uic-another_ui_file.hpp'],
147                 ['work1', 'mmmanother_ui_file.cxx'])
148
149 def _flagTest(test,fileToContentsStart):
150     for f,c in fileToContentsStart.items():
151         if test.read(test.workpath('work1', f)).find(c) != 0:
152             return 1
153     return 0
154
155 test.fail_test(_flagTest(test, {'mmmmocFromH.cxx':'/* mymoc.py -z */',
156                                 'mocmocFromCpp.inl':'/* mymoc.py -w */',
157                                 'an_ui_file.cxx':'/* myuic.py -x */',
158                                 'uic-an_ui_file.hpp':'/* myuic.py -y */',
159                                 'mmman_ui_file.cxx':'/* mymoc.py -z */'}))
160
161 test.write(['work2', 'SConstruct'], """
162 import os.path
163 env1 = Environment(tools=['qt'],
164                    QTDIR = r'%(QTDIR)s',
165                    QT_BINPATH='$QTDIR/bin64',
166                    QT_LIBPATH='$QTDIR/lib64',
167                    QT_CPPPATH='$QTDIR/h64')
168
169 cpppath = env1.subst('$CPPPATH')
170 if os.path.normpath(cpppath) != os.path.join(r'%(QTDIR)s', 'h64'):
171     print cpppath
172     Exit(1)
173 libpath = env1.subst('$LIBPATH')
174 if os.path.normpath(libpath) != os.path.join(r'%(QTDIR)s', 'lib64'):
175     print libpath
176     Exit(2)
177 qt_moc = env1.subst('$QT_MOC')
178 if os.path.normpath(qt_moc) != os.path.join(r'%(QTDIR)s', 'bin64', 'moc'):
179     print qt_moc
180     Exit(3)
181
182 env2 = Environment(tools=['default', 'qt'],
183                    QTDIR = None,
184                    QT_LIB = None,
185                    QT_CPPPATH = None,
186                    QT_LIBPATH = None)
187
188 env2.Program('main.cpp')
189 """ % {'QTDIR':QT})
190
191 test.write(['work2', 'main.cpp'], """
192 int main() { return 0; }
193 """)
194
195 # Ignore stderr, because if Qt is not installed,
196 # there may be a warning about an empty QTDIR on stderr.
197 test.run(chdir='work2', stderr=None)
198
199 test.must_exist(['work2', 'main' + _exe])
200
201 test.pass_test()
202
203 # Local Variables:
204 # tab-width:4
205 # indent-tabs-mode:nil
206 # End:
207 # vim: set expandtab tabstop=4 shiftwidth=4: