[ci skip] update generated files
[scons.git] / test / Batch / action-changed.py
blob771b87625005bf089fae5c459cf39d40b530c787
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 targets in a batch builder are rebuilt when the
28 build action changes.
29 """
31 import os
33 import TestSCons
35 # swap slashes because on py3 on win32 inside the generated build.py
36 # the backslashes are getting interpretted as unicode which is
37 # invalid.
38 python = TestSCons.python.replace('\\','//')
39 _python_ = TestSCons._python_
41 test = TestSCons.TestSCons()
43 build_py_contents = """\
44 #!/usr/bin/env %s
45 import sys
46 sep = sys.argv.index('--')
47 targets = sys.argv[1:sep]
48 sources = sys.argv[sep+1:]
49 for t, s in zip(targets, sources):
50 with open(t, 'wb') as ofp, open(s, 'rb') as ifp:
51 ofp.write(bytearray('%s\\n', 'utf-8'))
52 ofp.write(ifp.read())
53 sys.exit(0)
54 """
56 test.write('build.py', build_py_contents % (python, 'one'))
57 os.chmod(test.workpath('build.py'), 0o755)
59 build_py_workpath = test.workpath('build.py')
61 # Provide IMPLICIT_COMMAND_DEPENDENCIES=2 so we take a dependency on build.py.
62 # Without that, we only scan the first entry in the action string.
63 test.write('SConstruct', """
64 DefaultEnvironment(tools=[])
65 env = Environment(tools=[],
66 IMPLICIT_COMMAND_DEPENDENCIES=2)
67 env.PrependENVPath('PATHEXT', '.PY')
68 bb = Action(r'%(_python_)s "%(build_py_workpath)s" $CHANGED_TARGETS -- $CHANGED_SOURCES',
69 batch_key=True,
70 targets='CHANGED_TARGETS')
71 env['BUILDERS']['Batch'] = Builder(action=bb)
72 env.Batch('f1.out', 'f1.in')
73 env.Batch('f2.out', 'f2.in')
74 env.Batch('f3.out', 'f3.in')
75 """ % locals())
77 test.write('f1.in', "f1.in\n")
78 test.write('f2.in', "f2.in\n")
79 test.write('f3.in', "f3.in\n")
81 test.run(arguments = '.')
83 test.must_match('f1.out', "one\nf1.in\n")
84 test.must_match('f2.out', "one\nf2.in\n")
85 test.must_match('f3.out', "one\nf3.in\n")
87 test.up_to_date(arguments = '.')
89 test.write('build.py', build_py_contents % (python, 'two'))
90 os.chmod(test.workpath('build.py'), 0o755)
92 test.not_up_to_date(arguments = '.')
94 test.must_match('f1.out', "two\nf1.in\n")
95 test.must_match('f2.out', "two\nf2.in\n")
96 test.must_match('f3.out', "two\nf3.in\n")
98 test.pass_test()
100 # Local Variables:
101 # tab-width:4
102 # indent-tabs-mode:nil
103 # End:
104 # vim: set expandtab tabstop=4 shiftwidth=4: