[ci skip] add test framework reformat to .git-blame-ignore-revs
[scons.git] / test / Decider / content-timestamp-symlink.py
blob4e0c3b007b75c58fc979331f0b81847df7a89b08
1 #!/usr/bin/env python
3 # Copyright The SCons Foundation
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.
24 """
25 Test the content-timestamp decider (formerly known as md5-timestamp)
26 correctly detects modification of a source file which is a symlink.
27 """
29 import TestSCons
31 _python_ = TestSCons._python_
33 test = TestSCons.TestSCons()
35 if not test.platform_has_symlink():
36 test.skip_test('Symbolic links not reliably available on this platform, skipping test.\n')
38 # a dummy "compiler" for the builder
39 test.write('build.py', r"""
40 import sys
42 with open(sys.argv[1], 'wb') as ofp:
43 for infile in sys.argv[2:]:
44 with open (infile, 'rb') as ifp:
45 ofp.write(ifp.read())
46 sys.exit(0)
47 """)
49 test.write('SConstruct', """
50 DefaultEnvironment(tools=[])
51 Build = Builder(action=r'%(_python_)s build.py $TARGET $SOURCES')
52 env = Environment(tools=[], BUILDERS={'Build': Build})
53 env.Decider('content-timestamp')
54 env.Build(target='match1.out', source='match1.in')
55 env.Build(target='match2.out', source='match2.in')
56 """ % locals())
58 test.write('match1.in', 'match1.in\n')
59 test.symlink('match1.in', 'match2.in')
61 test.run(arguments='.')
62 test.must_match('match1.out', 'match1.in\n')
63 test.must_match('match2.out', 'match1.in\n')
65 # first make sure some time has elapsed, so a low-granularity timestamp
66 # doesn't fail to trigger
67 test.sleep()
68 # Now update the source file contents, both targets should rebuild
69 test.write('match1.in', 'match2.in\n')
71 test.run(arguments='.')
72 test.must_match('match1.out', 'match2.in\n', message="match1.out not rebuilt\n")
73 test.must_match('match2.out', 'match2.in\n', message="match2.out not rebuilt\n")
75 test.pass_test()
77 # Local Variables:
78 # tab-width:4
79 # indent-tabs-mode:nil
80 # End:
81 # vim: set expandtab tabstop=4 shiftwidth=4: