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