Updates and slight refactor in fix
[scons.git] / test / MSVC / generate-rc.py
blobfbf18e72656b21fd88e4b28408b330f05b9a181e
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 Test adding a src_builder to the RES builder so that RC files can
28 be generated.
29 """
31 import TestSCons
33 _python_ = TestSCons._python_
34 test = TestSCons.TestSCons()
36 fake_rc = test.workpath('fake_rc.py')
38 test.write(fake_rc, """\
39 import sys
41 with open(sys.argv[1], 'w') as fo, open(sys.argv[2], 'r') as fi:
42 fo.write("fake_rc.py\\n" + fi.read())
43 """)
45 test.write('SConstruct', """
46 def generate_rc(target, source, env):
47 t = str(target[0])
48 s = str(source[0])
49 with open(t, 'w') as fo, open(s, 'r') as fi:
50 fo.write('generate_rc\\n' + fi.read())
52 DefaultEnvironment(tools=[])
53 env = Environment(tools=['msvc'], RCCOM=r'%(_python_)s %(fake_rc)s $TARGET $SOURCE')
54 env['BUILDERS']['GenerateRC'] = Builder(
55 action=generate_rc, suffix='.rc', src_suffix='.in'
57 env['BUILDERS']['RES'].src_builder.append('GenerateRC')
59 env.RES('my.in')
60 """ % locals())
62 test.write('my.in', "my.in\n")
64 test.run(arguments='.')
65 test.must_match('my.rc', "generate_rc\nmy.in\n", mode='r')
66 test.must_match('my.res', "fake_rc.py\ngenerate_rc\nmy.in\n", mode='r')
68 test.pass_test()
70 # Local Variables:
71 # tab-width:4
72 # indent-tabs-mode:nil
73 # End:
74 # vim: set expandtab tabstop=4 shiftwidth=4: