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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
28 Test that we can generate Visual Studio 8.0 project (.vcproj) and
29 solution (.sln) files that look correct.
39 test = TestSCons.TestSCons()
41 if sys.platform != 'win32':
42 msg = "Skipping Visual Studio test on non-Windows platform '%s'\n" % sys.platform
45 expected_slnfile = """\
46 Microsoft Visual Studio Solution File, Format Version 9.00
48 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{E5466E26-0003-F18B-8F8A-BCD76C86388D}"
51 \tGlobalSection(SolutionConfigurationPlatforms) = preSolution
52 \t\tRelease|Win32 = Release|Win32
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
58 \tGlobalSection(SolutionProperties) = preSolution
59 \t\tHideSolutionNode = FALSE
64 expected_vcprojfile = """\
65 <?xml version="1.0" encoding="Windows-1252"?>
67 \tProjectType="Visual C++"
70 \tProjectGUID="<PROJECT_GUID>"
73 \tRootNamespace="Test"
74 \tKeyword="MakeFileProj">
83 \t\t\tName="Release|Win32"
84 \t\t\tConfigurationType="0"
86 \t\t\tATLMinimizesCRunTimeLibraryUsage="false"
89 \t\t\t\tName="VCNMakeTool"
90 \t\t\t\tBuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct Test.exe"
91 \t\t\t\tReBuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct Test.exe"
92 \t\t\t\tCleanCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -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=""
107 \t\t\tName="Header Files"
108 \t\t\tFilter="h;hpp;hxx;hm;inl">
110 \t\t\t\tRelativePath="sdk.h">
114 \t\t\tName="Local Headers"
115 \t\t\tFilter="h;hpp;hxx;hm;inl">
117 \t\t\t\tRelativePath="test.h">
121 \t\t\tName="Other Files"
124 \t\t\t\tRelativePath="readme.txt">
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">
131 \t\t\t\tRelativePath="test.rc">
135 \t\t\tName="Source Files"
136 \t\t\tFilter="cpp;c;cxx;l;y;def;odl;idl;hpj;bat">
138 \t\t\t\tRelativePath="test1.cpp">
141 \t\t\t\tRelativePath="test2.cpp">
145 \t\t\tRelativePath="<SCONSCRIPT>">
150 </VisualStudioProject>
155 SConscript_contents = """\
156 env=Environment(MSVS_VERSION = '8.0')
158 testsrc = ['test1.cpp', 'test2.cpp']
160 testlocalincs = ['test.h']
161 testresources = ['test.rc']
162 testmisc = ['readme.txt']
164 env.MSVSProject(target = 'Test.vcproj',
165 slnguid = '{SLNGUID}',
168 localincs = testlocalincs,
169 resources = testresources,
171 buildtarget = 'Test.exe',
179 test.write(['work1', 'SConstruct'], SConscript_contents)
181 test.run(chdir='work1', arguments="Test.vcproj")
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)
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)
195 test.run(chdir='work1', arguments='-c .')
197 test.must_not_exist(test.workpath('work1', 'Test.vcproj'))
198 test.must_not_exist(test.workpath('work1', 'Test.sln'))
200 test.run(chdir='work1', arguments='Test.vcproj')
202 test.must_exist(test.workpath('work1', 'Test.vcproj'))
203 test.must_exist(test.workpath('work1', 'Test.sln'))
205 test.run(chdir='work1', arguments='-c Test.sln')
207 test.must_not_exist(test.workpath('work1', 'Test.vcproj'))
208 test.must_not_exist(test.workpath('work1', 'Test.sln'))
212 # Test that running SCons with $PYTHON_ROOT in the environment
213 # changes the .vcproj output as expected.
214 os.environ['PYTHON_ROOT'] = 'xyzzy'
216 test.run(chdir='work1', arguments='Test.vcproj')
218 python = os.path.join('$(PYTHON_ROOT)', os.path.split(sys.executable)[1])
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',
224 # don't compare the pickled data
225 assert vcproj[:len(expect)] == expect, test.diff_substr(expect, vcproj)
227 os.environ['PYTHON_ROOT'] = ''
231 test.subdir('work2', ['work2', 'src'])
233 test.write(['work2', 'SConstruct'], """\
234 SConscript('src/SConscript', build_dir='build')
237 test.write(['work2', 'src', 'SConscript'], SConscript_contents)
239 test.run(chdir='work2', arguments=".")
241 vcproj = test.read(['work2', 'src', 'Test.vcproj'], 'r')
242 expect = test.msvs_substitute(expected_vcprojfile,
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)
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)
257 test.must_match(['work2', 'build', 'Test.vcproj'], """\
258 This is just a placeholder file.
259 The real project file is here:
261 """ % test.workpath('work2', 'src', 'Test.vcproj'),
264 test.must_match(['work2', 'build', 'Test.sln'], """\
265 This is just a placeholder file.
266 The real workspace file is here:
268 """ % test.workpath('work2', 'src', 'Test.sln'),
275 test.write(['work3', 'SConstruct'], """\
276 env=Environment(MSVS_VERSION = '8.0')
278 testsrc = ['test1.cpp', 'test2.cpp']
280 testlocalincs = ['test.h']
281 testresources = ['test.rc']
282 testmisc = ['readme.txt']
284 p = env.MSVSProject(target = 'Test.vcproj',
287 localincs = testlocalincs,
288 resources = testresources,
290 buildtarget = 'Test.exe',
292 auto_build_solution = 0)
294 env.MSVSSolution(target = 'Test.sln',
295 slnguid = '{SLNGUID}',
300 test.run(chdir='work3', arguments=".")
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)
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)
314 test.run(chdir='work3', arguments='-c .')
316 test.must_not_exist(test.workpath('work3', 'Test.vcproj'))
317 test.must_not_exist(test.workpath('work3', 'Test.sln'))
319 test.run(chdir='work3', arguments='.')
321 test.must_exist(test.workpath('work3', 'Test.vcproj'))
322 test.must_exist(test.workpath('work3', 'Test.sln'))
324 test.run(chdir='work3', arguments='-c Test.sln')
326 test.must_exist(test.workpath('work3', 'Test.vcproj'))
327 test.must_not_exist(test.workpath('work3', 'Test.sln'))
329 test.run(chdir='work3', arguments='-c Test.vcproj')
331 test.must_not_exist(test.workpath('work3', 'Test.vcproj'))