[ci skip] update generated files
[scons.git] / test / QT / qt3 / Tool.py
blob1b34ea2ab9156bcce3dad4675d89456b5d251bfa
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 Verify that applying env.Tool('qt3') after running Configure checks
28 works properly. This was broken in 0.96.95.
30 The configuration here is a moderately stripped-down version of the
31 real-world configuration for lprof (lprof.sourceforge.net). It's probably
32 not completely minimal, but we're leaving it as-is since it represents a
33 good real-world sanity check on the interaction of some key subsystems.
34 """
36 import os
38 import TestSCons
40 test = TestSCons.TestSCons()
42 if not os.environ.get('QTDIR', None):
43 x ="External environment variable $QTDIR not set; skipping test(s).\n"
44 test.skip_test(x)
46 test.write('SConstruct', """
47 import os
49 def DoWithVariables(variables, prefix, what):
50 saved_variables = { }
51 for name in variables.keys():
52 saved_variables[ name ] = env[ name ][:]
53 env[ name ].append(variables[ name ])
55 result = what()
57 for name in saved_variables.keys():
58 env[ name ] = saved_variables[ name ]
59 env[ prefix+name ] = variables[ name ]
61 return result
63 def CheckForQtAt(context, qtdir):
64 context.Message('Checking for Qt at %s... ' % qtdir)
65 libp = os.path.join(qtdir, 'lib')
66 cppp = os.path.join(qtdir, 'include')
67 result = AttemptLinkWithVariables(context,
68 { "LIBS": "qt-mt", "LIBPATH": libp , "CPPPATH": cppp },
69 '''
70 #include <qapplication.h>
71 int main(int argc, char **argv) {
72 QApplication qapp(argc, argv);
73 return 0;
75 ''',".cpp","QT_")
76 context.Result(result)
77 return result
79 def CheckForQt(context):
80 # list is currently POSIX centric - what happens with Windows?
81 potential_qt_dirs = [
82 "/usr/share/qt3", # Debian unstable
83 "/usr/share/qt",
84 "/usr",
85 "/usr/local",
86 "/usr/lib/qt3", # Suse
87 "/usr/lib/qt",
88 "/usr/qt/3", # Gentoo
89 "/usr/pkg/qt3" # pkgsrc (NetBSD)
92 if 'QTDIR' in os.environ:
93 potential_qt_dirs.insert(0, os.environ['QTDIR'])
95 if env[ 'qt_directory' ] != "/":
96 uic_path = os.path.join(env['qt_directory'], 'bin', 'uic')
97 if os.path.isfile(uic_path):
98 potential_qt_dirs.insert(0, env[ 'qt_directory' ])
99 else:
100 print("QT not found. Invalid qt_directory value - failed to find uic.")
101 return 0
103 for i in potential_qt_dirs:
104 context.env.Replace(QT3DIR = i)
105 if CheckForQtAt(context, i):
106 # additional checks to validate QT installation
107 if not os.path.isfile(os.path.join(i, 'bin', 'uic')):
108 print("QT - failed to find uic.")
109 return 0
110 if not os.path.isfile(os.path.join(i, 'bin', 'moc')):
111 print("QT - failed to find moc.")
112 return 0
113 if not os.path.exists(os.path.join(i, 'lib')):
114 print("QT - failed to find QT lib path.")
115 return 0
116 if not os.path.exists(os.path.join(i, 'include')):
117 print("QT - failed to find QT include path.")
118 return 0
119 return 1
120 else:
121 if i==env['qt_directory']:
122 print("QT directory not valid. Failed QT test build.")
123 return 0
124 return 0
126 def AttemptLinkWithVariables(context, variables, code, extension, prefix):
127 return DoWithVariables(variables, prefix,
128 lambda: context.TryLink(code, extension))
130 env = Environment(CPPPATH=['.'], LIBPATH=['.'], LIBS=[])
132 opts = Variables('lprof.conf')
133 opts.Add(PathVariable("qt_directory", "Path to Qt directory", "/"))
134 opts.Update(env)
136 env['QT3_LIB'] = 'qt-mt'
137 config = env.Configure(custom_tests = {
138 'CheckForQt' : CheckForQt,
141 if not config.CheckForQt():
142 print("Failed to find valid QT environment.")
143 Exit(1)
145 env.Tool('qt3', ['$TOOL_PATH'])
146 """)
148 test.run(arguments='.')
150 test.pass_test()
152 # Local Variables:
153 # tab-width:4
154 # indent-tabs-mode:nil
155 # End:
156 # vim: set expandtab tabstop=4 shiftwidth=4: