[ci skip] update generated files
[scons.git] / test / MSVC / batch.py
blob205a1810e411c0448f866d1392878f3015d8d9ba
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 operation of Visual C/C++ batch builds.
29 This uses a fake compiler and linker script, fake command lines, and
30 explicit suffix settings so that the test should work when run on any
31 platform.
32 """
34 import os
35 import TestSCons
37 test = TestSCons.TestSCons()
39 _python_ = TestSCons._python_
41 test.write('fake_cl.py', """\
42 import os
43 import sys
44 input_files = sys.argv[2:]
45 if sys.argv[1][-1] in (os.sep, '\\\\'):
46 # The output (/Fo) argument ends with a backslash, indicating an
47 # output directory. We accept ending with a slash as well so this
48 # test runs on non-Windows systems. Strip either character and
49 # record the directory name.
50 sys.argv[1] = sys.argv[1][:-1]
51 dir = sys.argv[1][3:]
52 else:
53 dir = None
54 output = sys.argv[1][3:]
55 # Delay writing the .log output until here so any trailing slash or
56 # backslash has been stripped, and the output comparisons later in this
57 # script don't have to account for the difference.
58 with open('fake_cl.log', 'a') as ofp:
59 ofp.write(" ".join(sys.argv[1:]) + '\\n')
60 for infile in input_files:
61 if dir:
62 outfile = os.path.join(dir, infile.replace('.c', '.obj'))
63 else:
64 outfile = output
65 with open(outfile, 'w') as ofp:
66 with open(infile, 'r') as ifp:
67 ofp.write(ifp.read())
68 """)
70 test.write('fake_link.py', """\
71 import sys
72 with open(sys.argv[1], 'w') as ofp:
73 for infile in sys.argv[2:]:
74 with open(infile, 'r') as ifp:
75 ofp.write(ifp.read())
76 """)
78 test.write('SConstruct', """
79 DefaultEnvironment(tools=[])
80 cccom = r'%(_python_)s fake_cl.py $_MSVC_OUTPUT_FLAG $CHANGED_SOURCES'
81 linkcom = r'%(_python_)s fake_link.py ${TARGET.windows} $SOURCES'
82 env = Environment(tools=['msvc', 'mslink'],
83 CCCOM=cccom,
84 LINKCOM=linkcom,
85 PROGSUFFIX='.exe',
86 OBJSUFFIX='.obj',
87 MSVC_BATCH=ARGUMENTS.get('MSVC_BATCH'))
88 p = env.Object('prog.c')
89 f1 = env.Object('f1.c')
90 f2 = env.Object('f2.c')
91 env.Program(p + f1 + f2)
92 """ % locals())
94 test.write('prog.c', "prog.c\n")
95 test.write('f1.c', "f1.c\n")
96 test.write('f2.c', "f2.c\n")
98 test.run(arguments='MSVC_BATCH=1 .')
99 test.must_match('prog.exe', "prog.c\nf1.c\nf2.c\n", mode='r')
100 test.must_match('fake_cl.log', """\
101 /Fo.%s prog.c f1.c f2.c
102 """%os.sep, mode='r')
103 test.up_to_date(options='MSVC_BATCH=1', arguments='.')
105 test.write('f1.c', "f1.c 2\n")
107 test.run(arguments='MSVC_BATCH=1 .')
108 test.must_match('prog.exe', "prog.c\nf1.c 2\nf2.c\n", mode='r')
109 test.must_match('fake_cl.log', """\
110 /Fo.%s prog.c f1.c f2.c
111 /Fo.%s f1.c
112 """%(os.sep, os.sep), mode='r')
113 test.up_to_date(options='MSVC_BATCH=1', arguments='.')
115 test.run(arguments='-c .')
116 test.unlink('fake_cl.log')
118 test.run(arguments='. MSVC_BATCH=0')
119 test.must_match('prog.exe', "prog.c\nf1.c 2\nf2.c\n", mode='r')
120 test.must_match('fake_cl.log', """\
121 /Fof1.obj f1.c
122 /Fof2.obj f2.c
123 /Foprog.obj prog.c
124 """, mode='r')
126 test.run(arguments='-c .')
127 test.unlink('fake_cl.log')
129 test.run(arguments='. MSVC_BATCH=False')
130 test.must_match('prog.exe', "prog.c\nf1.c 2\nf2.c\n", mode='r')
131 test.must_match('fake_cl.log', """\
132 /Fof1.obj f1.c
133 /Fof2.obj f2.c
134 /Foprog.obj prog.c
135 """, mode='r')
137 test.write('f1.c', "f1.c 3\n")
139 test.run(arguments='. MSVC_BATCH=0')
140 test.must_match('prog.exe', "prog.c\nf1.c 3\nf2.c\n", mode='r')
141 test.must_match('fake_cl.log', """\
142 /Fof1.obj f1.c
143 /Fof2.obj f2.c
144 /Foprog.obj prog.c
145 /Fof1.obj f1.c
146 """, mode='r')
148 test.pass_test()
150 # Local Variables:
151 # tab-width:4
152 # indent-tabs-mode:nil
153 # End:
154 # vim: set expandtab tabstop=4 shiftwidth=4: