Added fix for TeX includes with same name as subdirs.
[scons.git] / test / timestamp-fallback.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 falling back to 'timestamp' behavior if there is no native
29 hashlib and no underlying md5 module available.
30 """
31
32 import imp
33 import os
34
35 import TestSCons
36
37 test = TestSCons.TestSCons()
38
39 try:
40     file, name, desc = imp.find_module('hashlib')
41 except ImportError:
42     pass
43 else:
44     msg = "This version of Python has a 'hashlib' module.\n" + \
45           "Skipping test of falling back to timestamps.\n"
46     test.skip_test(msg)
47
48 try:
49     file, name, desc = imp.find_module('md5')
50 except ImportError:
51     pass
52 else:
53     if desc[2] == imp.C_BUILTIN:
54         msg = "The 'md5' module is built in to this version of Python.\n" + \
55               "Cannot test falling back to timestamps.\n"
56         test.skip_test(msg)
57
58 test.write('md5.py', r"""
59 raise ImportError
60 """)
61
62 os.environ['PYTHONPATH'] = test.workpath('.')
63
64 test.write('SConstruct', """
65 DefaultEnvironment(tools=[])
66 def build(env, target, source):
67     open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read())
68 B = Builder(action = build)
69 env = Environment(tools = [], BUILDERS = { 'B' : B })
70 env.B(target = 'f1.out', source = 'f1.in')
71 env.B(target = 'f2.out', source = 'f2.in')
72 env.B(target = 'f3.out', source = 'f3.in')
73 env.B(target = 'f4.out', source = 'f4.in')
74 """)
75
76 test.write('f1.in', "f1.in\n")
77 test.write('f2.in', "f2.in\n")
78 test.write('f3.in', "f3.in\n")
79 test.write('f4.in', "f4.in\n")
80
81 test.run(arguments = 'f1.out f3.out',
82          stderr = None)
83
84 test.run(arguments = 'f1.out f2.out f3.out f4.out',
85          stdout = test.wrap_stdout("""\
86 scons: `f1.out' is up to date.
87 build(["f2.out"], ["f2.in"])
88 scons: `f3.out' is up to date.
89 build(["f4.out"], ["f4.in"])
90 """),
91          stderr = None)
92
93 os.utime(test.workpath('f1.in'), 
94          (os.path.getatime(test.workpath('f1.in')),
95           os.path.getmtime(test.workpath('f1.in'))+10))
96 os.utime(test.workpath('f3.in'), 
97          (os.path.getatime(test.workpath('f3.in')),
98           os.path.getmtime(test.workpath('f3.in'))+10))
99
100 test.run(arguments = 'f1.out f2.out f3.out f4.out',
101          stdout = test.wrap_stdout("""\
102 build(["f1.out"], ["f1.in"])
103 scons: `f2.out' is up to date.
104 build(["f3.out"], ["f3.in"])
105 scons: `f4.out' is up to date.
106 """),
107          stderr = None)
108
109
110 test.pass_test()
111
112 # Local Variables:
113 # tab-width:4
114 # indent-tabs-mode:nil
115 # End:
116 # vim: set expandtab tabstop=4 shiftwidth=4: