Merged revisions 1582-1665 via svnmerge from
[scons.git] / test / MSVS / vs-8.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 8.0 project (.vcproj) and
29 solution (.sln) files that look correct.
30 """
31
32 import os
33 import os.path
34 import sys
35
36 import TestCmd
37 import TestSCons
38
39 test = TestSCons.TestSCons()
40
41 if sys.platform != 'win32':
42     msg = "Skipping Visual Studio test on non-Windows platform '%s'\n" % sys.platform
43     test.skip_test(msg)
44
45 expected_slnfile = """\
46 Microsoft Visual Studio Solution File, Format Version 9.00
47 # Visual Studio 2005
48 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{E5466E26-0003-F18B-8F8A-BCD76C86388D}"
49 EndProject
50 Global
51 \tGlobalSection(SolutionConfigurationPlatforms) = preSolution
52 \t\tRelease|Win32 = Release|Win32
53 \tEndGlobalSection
54 \tGlobalSection(ProjectConfigurationPlatforms) = postSolution
55 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release|Win32.ActiveCfg = Release|Win32
56 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release|Win32.Build.0 = Release|Win32
57 \tEndGlobalSection
58 \tGlobalSection(SolutionProperties) = preSolution
59 \t\tHideSolutionNode = FALSE
60 \tEndGlobalSection
61 EndGlobal
62 """
63
64 expected_vcprojfile = """\
65 <?xml version="1.0" encoding="Windows-1252"?>
66 <VisualStudioProject
67 \tProjectType="Visual C++"
68 \tVersion="8.00"
69 \tName="Test"
70 \tProjectGUID="<PROJECT_GUID>"
71 \tSccProjectName=""
72 \tSccLocalPath=""
73 \tRootNamespace="Test"
74 \tKeyword="MakeFileProj">
75 \t<Platforms>
76 \t\t<Platform
77 \t\t\tName="Win32"/>
78 \t</Platforms>
79 \t<ToolFiles>
80 \t</ToolFiles>
81 \t<Configurations>
82 \t\t<Configuration
83 \t\t\tName="Release|Win32"
84 \t\t\tConfigurationType="0"
85 \t\t\tUseOfMFC="0"
86 \t\t\tATLMinimizesCRunTimeLibraryUsage="false"
87 \t\t\t>
88 \t\t\t<Tool
89 \t\t\t\tName="VCNMakeTool"
90 \t\t\t\tBuildCommandLine="echo Starting SCons &amp;&amp; &quot;<PYTHON>&quot; -c &quot;<SCONS_SCRIPT_MAIN_XML>&quot; -C &quot;<WORKPATH>&quot; -f SConstruct Test.exe"
91 \t\t\t\tReBuildCommandLine="echo Starting SCons &amp;&amp; &quot;<PYTHON>&quot; -c &quot;<SCONS_SCRIPT_MAIN_XML>&quot; -C &quot;<WORKPATH>&quot; -f SConstruct Test.exe"
92 \t\t\t\tCleanCommandLine="echo Starting SCons &amp;&amp; &quot;<PYTHON>&quot; -c &quot;<SCONS_SCRIPT_MAIN_XML>&quot; -C &quot;<WORKPATH>&quot; -f SConstruct -c Test.exe"
93 \t\t\t\tOutput="Test.exe"
94 \t\t\t\tPreprocessorDefinitions=""
95 \t\t\t\tIncludeSearchPath=""
96 \t\t\t\tForcedIncludes=""
97 \t\t\t\tAssemblySearchPath=""
98 \t\t\t\tForcedUsingAssemblies=""
99 \t\t\t\tCompileAsManaged=""
100 \t\t\t/>
101 \t\t</Configuration>
102 \t</Configurations>
103 \t<References>
104 \t</References>
105 \t<Files>
106 \t\t<Filter
107 \t\t\tName="Header Files"
108 \t\t\tFilter="h;hpp;hxx;hm;inl">
109 \t\t\t<File
110 \t\t\t\tRelativePath="sdk.h">
111 \t\t\t</File>
112 \t\t</Filter>
113 \t\t<Filter
114 \t\t\tName="Local Headers"
115 \t\t\tFilter="h;hpp;hxx;hm;inl">
116 \t\t\t<File
117 \t\t\t\tRelativePath="test.h">
118 \t\t\t</File>
119 \t\t</Filter>
120 \t\t<Filter
121 \t\t\tName="Other Files"
122 \t\t\tFilter="">
123 \t\t\t<File
124 \t\t\t\tRelativePath="readme.txt">
125 \t\t\t</File>
126 \t\t</Filter>
127 \t\t<Filter
128 \t\t\tName="Resource Files"
129 \t\t\tFilter="r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
130 \t\t\t<File
131 \t\t\t\tRelativePath="test.rc">
132 \t\t\t</File>
133 \t\t</Filter>
134 \t\t<Filter
135 \t\t\tName="Source Files"
136 \t\t\tFilter="cpp;c;cxx;l;y;def;odl;idl;hpj;bat">
137 \t\t\t<File
138 \t\t\t\tRelativePath="test1.cpp">
139 \t\t\t</File>
140 \t\t\t<File
141 \t\t\t\tRelativePath="test2.cpp">
142 \t\t\t</File>
143 \t\t</Filter>
144 \t\t<File
145 \t\t\tRelativePath="<SCONSCRIPT>">
146 \t\t</File>
147 \t</Files>
148 \t<Globals>
149 \t</Globals>
150 </VisualStudioProject>
151 """
152
153
154
155 SConscript_contents = """\
156 env=Environment(tools=['msvs'], MSVS_VERSION = '8.0')
157
158 testsrc = ['test1.cpp', 'test2.cpp']
159 testincs = ['sdk.h']
160 testlocalincs = ['test.h']
161 testresources = ['test.rc']
162 testmisc = ['readme.txt']
163
164 env.MSVSProject(target = 'Test.vcproj',
165                 slnguid = '{SLNGUID}',
166                 srcs = testsrc,
167                 incs = testincs,
168                 localincs = testlocalincs,
169                 resources = testresources,
170                 misc = testmisc,
171                 buildtarget = 'Test.exe',
172                 variant = 'Release')
173 """
174
175
176
177 test.subdir('work1')
178
179 test.write(['work1', 'SConstruct'], SConscript_contents)
180
181 test.run(chdir='work1', arguments="Test.vcproj")
182
183 test.must_exist(test.workpath('work1', 'Test.vcproj'))
184 vcproj = test.read(['work1', 'Test.vcproj'], 'r')
185 expect = test.msvs_substitute(expected_vcprojfile, '8.0', 'work1', 'SConstruct')
186 # don't compare the pickled data
187 assert vcproj[:len(expect)] == expect, test.diff_substr(expect, vcproj)
188
189 test.must_exist(test.workpath('work1', 'Test.sln'))
190 sln = test.read(['work1', 'Test.sln'], 'r')
191 expect = test.msvs_substitute(expected_slnfile, '8.0', 'work1', 'SConstruct')
192 # don't compare the pickled data
193 assert sln[:len(expect)] == expect, test.diff_substr(expect, sln)
194
195 test.run(chdir='work1', arguments='-c .')
196
197 test.must_not_exist(test.workpath('work1', 'Test.vcproj'))
198 test.must_not_exist(test.workpath('work1', 'Test.sln'))
199
200 test.run(chdir='work1', arguments='Test.vcproj')
201
202 test.must_exist(test.workpath('work1', 'Test.vcproj'))
203 test.must_exist(test.workpath('work1', 'Test.sln'))
204
205 test.run(chdir='work1', arguments='-c Test.sln')
206
207 test.must_not_exist(test.workpath('work1', 'Test.vcproj'))
208 test.must_not_exist(test.workpath('work1', 'Test.sln'))
209
210
211
212 # Test that running SCons with $PYTHON_ROOT in the environment
213 # changes the .vcproj output as expected.
214 os.environ['PYTHON_ROOT'] = 'xyzzy'
215
216 test.run(chdir='work1', arguments='Test.vcproj')
217
218 python = os.path.join('$(PYTHON_ROOT)', os.path.split(TestSCons.python)[1])
219
220 test.must_exist(test.workpath('work1', 'Test.vcproj'))
221 vcproj = test.read(['work1', 'Test.vcproj'], 'r')
222 expect = test.msvs_substitute(expected_vcprojfile, '8.0', 'work1', 'SConstruct',
223                               python=python)
224 # don't compare the pickled data
225 assert vcproj[:len(expect)] == expect, test.diff_substr(expect, vcproj)
226
227 os.environ['PYTHON_ROOT'] = ''
228
229
230
231 test.subdir('work2', ['work2', 'src'])
232
233 test.write(['work2', 'SConstruct'], """\
234 SConscript('src/SConscript', build_dir='build')
235 """)
236
237 test.write(['work2', 'src', 'SConscript'], SConscript_contents)
238
239 test.run(chdir='work2', arguments=".")
240
241 vcproj = test.read(['work2', 'src', 'Test.vcproj'], 'r')
242 expect = test.msvs_substitute(expected_vcprojfile,
243                               '7.0',
244                               'work2',
245                               'SConstruct',
246                               project_guid="{25F6CE89-8E22-2910-8B6E-FFE6DC1E2792}")
247 # don't compare the pickled data
248 assert vcproj[:len(expect)] == expect, test.diff_substr(expect, vcproj)
249
250 test.must_exist(test.workpath('work2', 'src', 'Test.sln'))
251 sln = test.read(['work2', 'src', 'Test.sln'], 'r')
252 expect = test.msvs_substitute(expected_slnfile, '7.0',
253                               os.path.join('work2', 'src'))
254 # don't compare the pickled data
255 assert sln[:len(expect)] == expect, test.diff_substr(expect, sln)
256
257 test.must_match(['work2', 'build', 'Test.vcproj'], """\
258 This is just a placeholder file.
259 The real project file is here:
260 %s
261 """ % test.workpath('work2', 'src', 'Test.vcproj'),
262                 mode='r')
263
264 test.must_match(['work2', 'build', 'Test.sln'], """\
265 This is just a placeholder file.
266 The real workspace file is here:
267 %s
268 """ % test.workpath('work2', 'src', 'Test.sln'),
269                 mode='r')
270
271
272
273 test.subdir('work3')
274
275 test.write(['work3', 'SConstruct'], """\
276 env=Environment(tools=['msvs'], MSVS_VERSION = '8.0')
277
278 testsrc = ['test1.cpp', 'test2.cpp']
279 testincs = ['sdk.h']
280 testlocalincs = ['test.h']
281 testresources = ['test.rc']
282 testmisc = ['readme.txt']
283
284 p = env.MSVSProject(target = 'Test.vcproj',
285                     srcs = testsrc,
286                     incs = testincs,
287                     localincs = testlocalincs,
288                     resources = testresources,
289                     misc = testmisc,
290                     buildtarget = 'Test.exe',
291                     variant = 'Release',
292                     auto_build_solution = 0)
293
294 env.MSVSSolution(target = 'Test.sln',
295                  slnguid = '{SLNGUID}',
296                  projects = [p],
297                  variant = 'Release')
298 """)
299
300 test.run(chdir='work3', arguments=".")
301
302 test.must_exist(test.workpath('work3', 'Test.vcproj'))
303 vcproj = test.read(['work3', 'Test.vcproj'], 'r')
304 expect = test.msvs_substitute(expected_vcprojfile, '8.0', 'work3', 'SConstruct')
305 # don't compare the pickled data
306 assert vcproj[:len(expect)] == expect, test.diff_substr(expect, vcproj)
307
308 test.must_exist(test.workpath('work3', 'Test.sln'))
309 sln = test.read(['work3', 'Test.sln'], 'r')
310 expect = test.msvs_substitute(expected_slnfile, '8.0', 'work3', 'SConstruct')
311 # don't compare the pickled data
312 assert sln[:len(expect)] == expect, test.diff_substr(expect, sln)
313
314 test.run(chdir='work3', arguments='-c .')
315
316 test.must_not_exist(test.workpath('work3', 'Test.vcproj'))
317 test.must_not_exist(test.workpath('work3', 'Test.sln'))
318
319 test.run(chdir='work3', arguments='.')
320
321 test.must_exist(test.workpath('work3', 'Test.vcproj'))
322 test.must_exist(test.workpath('work3', 'Test.sln'))
323
324 test.run(chdir='work3', arguments='-c Test.sln')
325
326 test.must_exist(test.workpath('work3', 'Test.vcproj'))
327 test.must_not_exist(test.workpath('work3', 'Test.sln'))
328
329 test.run(chdir='work3', arguments='-c Test.vcproj')
330
331 test.must_not_exist(test.workpath('work3', 'Test.vcproj'))
332
333
334
335 test.pass_test()