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.
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
37 test
= TestSCons
.TestSCons()
39 _python_
= TestSCons
._python
_
41 test
.write('fake_cl.py', """\
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]
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:
62 outfile = os.path.join(dir, infile.replace('.c', '.obj'))
65 with open(outfile, 'w') as ofp:
66 with open(infile, 'r') as ifp:
70 test
.write('fake_link.py', """\
72 with open(sys.argv[1], 'w') as ofp:
73 for infile in sys.argv[2:]:
74 with open(infile, 'r') as ifp:
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'],
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)
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
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', """\
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', """\
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', """\
152 # indent-tabs-mode:nil
154 # vim: set expandtab tabstop=4 shiftwidth=4: