04e7c9323021ad8079c46fb9e75f666d1b1870b3
[scons.git] / test / MSVS / vs-6.0-files.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 Test that we can generate Visual Studio 6 project (.dsp) and solution
29 (.dsw) files that look correct.
30 """
31
32 import os
33 import sys
34
35 import TestCmd
36 import TestSCons
37
38 test = TestSCons.TestSCons()
39
40 if sys.platform != 'win32':
41     msg = "Skipping Visual Studio test on non-Windows platform '%s'\n" % sys.platform
42     test.skip_test(msg)
43
44
45
46 expected_dspfile = '''\
47 # Microsoft Developer Studio Project File - Name="Test" - Package Owner=<4>
48 # Microsoft Developer Studio Generated Build File, Format Version 6.00
49 # ** DO NOT EDIT **
50
51 # TARGTYPE "Win32 (x86) External Target" 0x0106
52
53 CFG=Test - Win32 Release
54 !MESSAGE This is not a valid makefile. To build this project using NMAKE,
55 !MESSAGE use the Export Makefile command and run
56 !MESSAGE 
57 !MESSAGE NMAKE /f "Test.mak".
58 !MESSAGE 
59 !MESSAGE You can specify a configuration when running NMAKE
60 !MESSAGE by defining the macro CFG on the command line. For example:
61 !MESSAGE 
62 !MESSAGE NMAKE /f "Test.mak" CFG="Test - Win32 Release"
63 !MESSAGE 
64 !MESSAGE Possible choices for configuration are:
65 !MESSAGE 
66 !MESSAGE "Test - Win32 Release" (based on "Win32 (x86) External Target")
67 !MESSAGE 
68
69 # Begin Project
70 # PROP AllowPerConfigDependencies 0
71 # PROP Scc_ProjName ""
72 # PROP Scc_LocalPath ""
73
74 !IF  "$(CFG)" == "Test - Win32 Release"
75
76 # PROP BASE Use_MFC 0
77 # PROP BASE Use_Debug_Libraries 0
78 # PROP BASE Output_Dir ""
79 # PROP BASE Intermediate_Dir ""
80 # PROP BASE Cmd_Line "echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
81 # PROP BASE Rebuild_Opt "-c && echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
82 # PROP BASE Target_File "Test.exe"
83 # PROP BASE Bsc_Name ""
84 # PROP BASE Target_Dir ""
85 # PROP Use_MFC 0
86 # PROP Use_Debug_Libraries 0
87 # PROP Output_Dir ""
88 # PROP Intermediate_Dir ""
89 # PROP Cmd_Line "echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
90 # PROP Rebuild_Opt "-c && echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
91 # PROP Target_File "Test.exe"
92 # PROP Bsc_Name ""
93 # PROP Target_Dir ""
94
95 !ENDIF
96
97 # Begin Target
98
99 # Name "Test - Win32 Release"
100
101 !IF  "$(CFG)" == "Test - Win32 Release"
102
103 !ENDIF 
104
105 # Begin Group "Header Files"
106
107 # PROP Default_Filter "h;hpp;hxx;hm;inl"
108 # Begin Source File
109
110 SOURCE="sdk.h"
111 # End Source File
112 # End Group
113 # Begin Group "Local Headers"
114
115 # PROP Default_Filter "h;hpp;hxx;hm;inl"
116 # Begin Source File
117
118 SOURCE="test.h"
119 # End Source File
120 # End Group
121 # Begin Group "Other Files"
122
123 # PROP Default_Filter ""
124 # Begin Source File
125
126 SOURCE="readme.txt"
127 # End Source File
128 # End Group
129 # Begin Group "Resource Files"
130
131 # PROP Default_Filter "r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
132 # Begin Source File
133
134 SOURCE="test.rc"
135 # End Source File
136 # End Group
137 # Begin Group "Source Files"
138
139 # PROP Default_Filter "cpp;c;cxx;l;y;def;odl;idl;hpj;bat"
140 # Begin Source File
141
142 SOURCE="test.c"
143 # End Source File
144 # End Group
145 # Begin Source File
146
147 SOURCE="<SCONSCRIPT>"
148 # End Source File
149 # End Target
150 # End Project
151 '''
152
153 expected_dswfile = '''\
154 Microsoft Developer Studio Workspace File, Format Version 6.00
155 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
156
157 ###############################################################################
158
159 Project: "Test"="Test.dsp" - Package Owner=<4>
160
161 Package=<5>
162 {{{
163 }}}
164
165 Package=<4>
166 {{{
167 }}}
168
169 ###############################################################################
170
171 Global:
172
173 Package=<5>
174 {{{
175 }}}
176
177 Package=<3>
178 {{{
179 }}}
180
181 ###############################################################################
182 '''
183
184
185
186 SConscript_contents = """\
187 env=Environment(tools=['msvs'], MSVS_VERSION = '6.0')
188
189 testsrc = ['test.c']
190 testincs = ['sdk.h']
191 testlocalincs = ['test.h']
192 testresources = ['test.rc']
193 testmisc = ['readme.txt']
194
195 env.MSVSProject(target = 'Test.dsp',
196                 srcs = testsrc,
197                 incs = testincs,
198                 localincs = testlocalincs,
199                 resources = testresources,
200                 misc = testmisc,
201                 buildtarget = 'Test.exe',
202                 variant = 'Release')
203 """
204
205
206
207 test.subdir('work1')
208
209 test.write(['work1', 'SConstruct'], SConscript_contents)
210
211 test.run(chdir='work1', arguments="Test.dsp")
212
213 test.must_exist(test.workpath('work1', 'Test.dsp'))
214 dsp = test.read(['work1', 'Test.dsp'], 'r')
215 expect = test.msvs_substitute(expected_dspfile, '6.0', 'work1', 'SConstruct')
216 # don't compare the pickled data
217 assert dsp[:len(expect)] == expect, test.diff_substr(expect, dsp)
218
219 test.must_exist(test.workpath('work1', 'Test.dsw'))
220 dsw = test.read(['work1', 'Test.dsw'], 'r')
221 expect = test.msvs_substitute(expected_dswfile, '6.0', 'work1', 'SConstruct')
222 assert dsw == expect, test.diff_substr(expect, dsw)
223
224 test.run(chdir='work1', arguments='-c .')
225
226 test.must_not_exist(test.workpath('work1', 'Test.dsp'))
227 test.must_not_exist(test.workpath('work1', 'Test.dsw'))
228
229 test.run(chdir='work1', arguments='Test.dsp')
230
231 test.must_exist(test.workpath('work1', 'Test.dsp'))
232 test.must_exist(test.workpath('work1', 'Test.dsw'))
233
234 test.run(chdir='work1', arguments='-c Test.dsw')
235
236 test.must_not_exist(test.workpath('work1', 'Test.dsp'))
237 test.must_not_exist(test.workpath('work1', 'Test.dsw'))
238
239
240
241 test.subdir('work2', ['work2', 'src'])
242
243 test.write(['work2', 'SConstruct'], """\
244 SConscript('src/SConscript', build_dir='build')
245 """)
246
247 test.write(['work2', 'src', 'SConscript'], SConscript_contents)
248
249 test.run(chdir='work2', arguments=".")
250
251 dsp = test.read(['work2', 'src', 'Test.dsp'], 'r')
252 expect = test.msvs_substitute(expected_dspfile, '6.0', 'work2', 'SConstruct')
253 # don't compare the pickled data
254 assert dsp[:len(expect)] == expect, test.diff_substr(expect, dsp)
255
256 test.must_exist(test.workpath('work2', 'src', 'Test.dsw'))
257 dsw = test.read(['work2', 'src', 'Test.dsw'], 'r')
258 expect = test.msvs_substitute(expected_dswfile, '6.0',
259                               os.path.join('work2', 'src'))
260 assert dsw == expect, test.diff_substr(expect, dsw)
261
262 test.must_match(['work2', 'build', 'Test.dsp'], """\
263 This is just a placeholder file.
264 The real project file is here:
265 %s
266 """ % test.workpath('work2', 'src', 'Test.dsp'),
267                 mode='r')
268
269 test.must_match(['work2', 'build', 'Test.dsw'], """\
270 This is just a placeholder file.
271 The real workspace file is here:
272 %s
273 """ % test.workpath('work2', 'src', 'Test.dsw'),
274                 mode='r')
275
276
277
278 test.subdir('work3')
279
280 test.write(['work3', 'SConstruct'], """\
281 env=Environment(tools=['msvs'], MSVS_VERSION = '6.0')
282
283 testsrc = ['test.c']
284 testincs = ['sdk.h']
285 testlocalincs = ['test.h']
286 testresources = ['test.rc']
287 testmisc = ['readme.txt']
288
289 p = env.MSVSProject(target = 'Test.dsp',
290                     srcs = testsrc,
291                     incs = testincs,
292                     localincs = testlocalincs,
293                     resources = testresources,
294                     misc = testmisc,
295                     buildtarget = 'Test.exe',
296                     variant = 'Release',
297                     auto_build_solution = 0)
298
299 env.MSVSSolution(target = 'Test.dsw',
300                  slnguid = '{SLNGUID}',
301                  projects = [p],
302                  variant = 'Release')
303 """)
304
305 test.run(chdir='work3', arguments=".")
306
307 test.must_exist(test.workpath('work3', 'Test.dsp'))
308 dsp = test.read(['work3', 'Test.dsp'], 'r')
309 expect = test.msvs_substitute(expected_dspfile, '6.0', 'work3', 'SConstruct')
310 # don't compare the pickled data
311 assert dsp[:len(expect)] == expect, test.diff_substr(expect, dsp)
312
313 test.must_exist(test.workpath('work3', 'Test.dsw'))
314 dsw = test.read(['work3', 'Test.dsw'], 'r')
315 expect = test.msvs_substitute(expected_dswfile, '6.0', 'work3', 'SConstruct')
316 assert dsw == expect, test.diff_substr(expect, dsw)
317
318 test.run(chdir='work3', arguments='-c .')
319
320 test.must_not_exist(test.workpath('work3', 'Test.dsp'))
321 test.must_not_exist(test.workpath('work3', 'Test.dsw'))
322
323 test.run(chdir='work3', arguments='.')
324
325 test.must_exist(test.workpath('work3', 'Test.dsp'))
326 test.must_exist(test.workpath('work3', 'Test.dsw'))
327
328 test.run(chdir='work3', arguments='-c Test.dsw')
329
330 test.must_exist(test.workpath('work3', 'Test.dsp'))
331 test.must_not_exist(test.workpath('work3', 'Test.dsw'))
332
333 test.run(chdir='work3', arguments='-c Test.dsp')
334
335 test.must_not_exist(test.workpath('work3', 'Test.dsp'))
336
337
338
339 test.pass_test()