Applied Benoit Belley's patch in ticket 1957 improve the robustness of
[scons.git] / test / Configure / VariantDir-SConscript.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 Verify that Configure calls in SConscript files work when used
29 with VariantDir.
30 """
31
32 import os.path
33
34 import TestSCons
35
36 _obj = TestSCons._obj
37
38 test = TestSCons.TestSCons(match = TestSCons.match_re_dotall)
39
40 test.subdir( 'sub', ['sub', 'local'] )
41
42 NCR = test.NCR  # non-cached rebuild
43 CR  = test.CR   # cached rebuild (up to date)
44 NCF = test.NCF  # non-cached build failure
45 CF  = test.CF   # cached build failure
46
47 test.write('SConstruct', """\
48 opts = Variables()
49 opts.Add('chdir')
50 env = Environment(options=opts)
51 if env['chdir'] == 'yes':
52   SConscriptChdir(1)
53 else:
54   SConscriptChdir(0)
55 VariantDir( 'build', '.' )
56 SConscript( 'build/SConscript' )
57 """)
58
59 test.write(['sub', 'local', 'local_header.h'], "/* Hello World */" )
60
61 test.write('SConscript', """\
62 SConscript( 'sub/SConscript' )
63 """)
64
65 test.write(['sub', 'SConscript'], """\
66 def CustomTest(context):
67   context.Message('Executing Custom Test ... ')
68   ret = context.TryCompile('#include "local_header.h"', '.c')
69   context.Result(ret)
70   return ret
71
72 env = Environment(FOO='fff')
73 env.Append( CPPPATH='local' )
74 import os
75 env.AppendENVPath('PATH', os.environ['PATH'])
76 conf = Configure( env, custom_tests = {'CustomTest' : CustomTest,
77                                        '$FOO' : CustomTest} )
78 if hasattr(conf, 'fff'):
79   conf.Message('$FOO should not have been expanded!')
80   Exit(1)
81 if not conf.CheckCHeader( 'math.h' ):
82   Exit(1)
83 if conf.CheckCHeader( 'no_std_c_header.h' ):
84   Exit(1)
85 if not conf.CustomTest():
86   Exit(1)
87 env = conf.Finish()
88 env.Program( 'TestProgram', 'TestProgram.c' )
89 """)
90
91 test.write(['sub', 'TestProgram.h'], """\
92 /* Just a test header */
93 """)
94
95 test.write(['sub', 'TestProgram.c'], """\
96 #include "TestProgram.h"
97 #include <stdio.h>
98
99 int main() {
100   printf( "Hello\\n" );
101 }
102 """)
103
104 # first with SConscriptChdir(0)
105 test.run(arguments='chdir=no')
106 test.checkLogAndStdout( ["Checking for C header file math.h... ",
107                         "Checking for C header file no_std_c_header.h... ",
108                         "Executing Custom Test ... "],
109                         ["yes", "no", "yes"],
110                         [[((".c", NCR), (_obj, NCR))],
111                          [((".c", NCR), (_obj, NCF))],
112                          [((".c", NCR), (_obj, NCR))]],
113                         "config.log",
114                         ".sconf_temp",
115                         os.path.join("build", "sub", "SConscript"))
116
117 test.run(arguments='chdir=no')
118 test.checkLogAndStdout( ["Checking for C header file math.h... ",
119                         "Checking for C header file no_std_c_header.h... ",
120                         "Executing Custom Test ... "],
121                         ["yes", "no", "yes"],
122                         [[((".c", CR), (_obj, CR))],
123                          [((".c", CR), (_obj, CF))],
124                          [((".c", CR), (_obj, CR))]],
125                         "config.log",
126                         ".sconf_temp",
127                         os.path.join("build", "sub", "SConscript"))
128
129 import shutil
130 shutil.rmtree(test.workpath(".sconf_temp"))
131 test.unlink(".sconsign.dblite")
132
133 # now with SConscriptChdir(1)
134 test.run(arguments='chdir=yes')
135 test.checkLogAndStdout( ["Checking for C header file math.h... ",
136                         "Checking for C header file no_std_c_header.h... ",
137                         "Executing Custom Test ... "],
138                         ["yes", "no", "yes"],
139                         [[((".c", NCR), (_obj, NCR))],
140                          [((".c", NCR), (_obj, NCF))],
141                          [((".c", NCR), (_obj, NCR))]],
142                         "config.log",
143                         ".sconf_temp",
144                         os.path.join("build", "sub", "SConscript"))
145
146 test.run(arguments='chdir=yes')
147 test.checkLogAndStdout( ["Checking for C header file math.h... ",
148                         "Checking for C header file no_std_c_header.h... ",
149                         "Executing Custom Test ... "],
150                         ["yes", "no", "yes"],
151                         [[((".c", CR), (_obj, CR))],
152                          [((".c", CR), (_obj, CF))],
153                          [((".c", CR), (_obj, CR))]],
154                         "config.log",
155                         ".sconf_temp",
156                         os.path.join("build", "sub", "SConscript"))
157
158
159 test.pass_test()