2 TestSConsMSVS.py: a testing framework for the SCons software construction
5 A TestSConsMSVS environment object is created via the usual invocation:
9 TestSConsMSVS is a subsclass of TestSCons, which is in turn a subclass
10 of TestCommon, which is in turn is a subclass of TestCmd), and hence
11 has available all of the methods and attributes from those classes,
12 as well as any overridden or additional methods or attributes defined
18 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
23 from TestSCons import *
24 from TestSCons import __all__
28 expected_dspfile_6_0 = '''\
29 # Microsoft Developer Studio Project File - Name="Test" - Package Owner=<4>
30 # Microsoft Developer Studio Generated Build File, Format Version 6.00
33 # TARGTYPE "Win32 (x86) External Target" 0x0106
35 CFG=Test - Win32 Release
36 !MESSAGE This is not a valid makefile. To build this project using NMAKE,
37 !MESSAGE use the Export Makefile command and run
39 !MESSAGE NMAKE /f "Test.mak".
41 !MESSAGE You can specify a configuration when running NMAKE
42 !MESSAGE by defining the macro CFG on the command line. For example:
44 !MESSAGE NMAKE /f "Test.mak" CFG="Test - Win32 Release"
46 !MESSAGE Possible choices for configuration are:
48 !MESSAGE "Test - Win32 Release" (based on "Win32 (x86) External Target")
52 # PROP AllowPerConfigDependencies 0
53 # PROP Scc_ProjName ""
54 # PROP Scc_LocalPath ""
56 !IF "$(CFG)" == "Test - Win32 Release"
59 # PROP BASE Use_Debug_Libraries 0
60 # PROP BASE Output_Dir ""
61 # PROP BASE Intermediate_Dir ""
62 # PROP BASE Cmd_Line "echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
63 # PROP BASE Rebuild_Opt "-c && echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
64 # PROP BASE Target_File "Test.exe"
65 # PROP BASE Bsc_Name ""
66 # PROP BASE Target_Dir ""
68 # PROP Use_Debug_Libraries 0
70 # PROP Intermediate_Dir ""
71 # PROP Cmd_Line "echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
72 # PROP Rebuild_Opt "-c && echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
73 # PROP Target_File "Test.exe"
81 # Name "Test - Win32 Release"
83 !IF "$(CFG)" == "Test - Win32 Release"
87 # Begin Group "Header Files"
89 # PROP Default_Filter "h;hpp;hxx;hm;inl"
95 # Begin Group "Local Headers"
97 # PROP Default_Filter "h;hpp;hxx;hm;inl"
103 # Begin Group "Other Files"
105 # PROP Default_Filter ""
111 # Begin Group "Resource Files"
113 # PROP Default_Filter "r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
119 # Begin Group "Source Files"
121 # PROP Default_Filter "cpp;c;cxx;l;y;def;odl;idl;hpj;bat"
129 SOURCE="<SCONSCRIPT>"
135 expected_dswfile_6_0 = '''\
136 Microsoft Developer Studio Workspace File, Format Version 6.00
137 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
139 ###############################################################################
141 Project: "Test"="Test.dsp" - Package Owner=<4>
151 ###############################################################################
163 ###############################################################################
166 SConscript_contents_6_0 = """\
167 env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='6.0')
171 testlocalincs = ['test.h']
172 testresources = ['test.rc']
173 testmisc = ['readme.txt']
175 env.MSVSProject(target = 'Test.dsp',
178 localincs = testlocalincs,
179 resources = testresources,
181 buildtarget = 'Test.exe',
187 expected_slnfile_7_0 = """\
188 Microsoft Visual Studio Solution File, Format Version 7.00
189 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{E5466E26-0003-F18B-8F8A-BCD76C86388D}"
192 \tGlobalSection(SolutionConfiguration) = preSolution
193 \t\tConfigName.0 = Release
195 \tGlobalSection(ProjectDependencies) = postSolution
197 \tGlobalSection(ProjectConfiguration) = postSolution
198 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release.ActiveCfg = Release|Win32
199 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release.Build.0 = Release|Win32
201 \tGlobalSection(ExtensibilityGlobals) = postSolution
203 \tGlobalSection(ExtensibilityAddIns) = postSolution
208 expected_vcprojfile_7_0 = """\
209 <?xml version="1.0" encoding = "Windows-1252"?>
211 \tProjectType="Visual C++"
217 \tKeyword="MakeFileProj">
224 \t\t\tName="Release|Win32"
225 \t\t\tOutputDirectory=""
226 \t\t\tIntermediateDirectory=""
227 \t\t\tConfigurationType="0"
229 \t\t\tATLMinimizesCRunTimeLibraryUsage="FALSE">
231 \t\t\t\tName="VCNMakeTool"
232 \t\t\t\tBuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct "Test.exe""
233 \t\t\t\tCleanCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct -c "Test.exe""
234 \t\t\t\tRebuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct "Test.exe""
235 \t\t\t\tOutput="Test.exe"/>
240 \t\t\tName="Header Files"
241 \t\t\tFilter="h;hpp;hxx;hm;inl">
243 \t\t\t\tRelativePath="sdk.h">
247 \t\t\tName="Local Headers"
248 \t\t\tFilter="h;hpp;hxx;hm;inl">
250 \t\t\t\tRelativePath="test.h">
254 \t\t\tName="Other Files"
257 \t\t\t\tRelativePath="readme.txt">
261 \t\t\tName="Resource Files"
262 \t\t\tFilter="r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
264 \t\t\t\tRelativePath="test.rc">
268 \t\t\tName="Source Files"
269 \t\t\tFilter="cpp;c;cxx;l;y;def;odl;idl;hpj;bat">
271 \t\t\t\tRelativePath="test1.cpp">
274 \t\t\t\tRelativePath="test2.cpp">
278 \t\t\tRelativePath="<SCONSCRIPT>">
283 </VisualStudioProject>
286 SConscript_contents_7_0 = """\
287 env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='7.0')
289 testsrc = ['test1.cpp', 'test2.cpp']
291 testlocalincs = ['test.h']
292 testresources = ['test.rc']
293 testmisc = ['readme.txt']
295 env.MSVSProject(target = 'Test.vcproj',
296 slnguid = '{SLNGUID}',
299 localincs = testlocalincs,
300 resources = testresources,
302 buildtarget = 'Test.exe',
308 expected_slnfile_7_1 = """\
309 Microsoft Visual Studio Solution File, Format Version 8.00
310 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{E5466E26-0003-F18B-8F8A-BCD76C86388D}"
311 \tProjectSection(ProjectDependencies) = postProject
315 \tGlobalSection(SolutionConfiguration) = preSolution
316 \t\tConfigName.0 = Release
318 \tGlobalSection(ProjectConfiguration) = postSolution
319 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release.ActiveCfg = Release|Win32
320 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release.Build.0 = Release|Win32
322 \tGlobalSection(ExtensibilityGlobals) = postSolution
324 \tGlobalSection(ExtensibilityAddIns) = postSolution
329 expected_vcprojfile_7_1 = """\
330 <?xml version="1.0" encoding = "Windows-1252"?>
332 \tProjectType="Visual C++"
338 \tKeyword="MakeFileProj">
345 \t\t\tName="Release|Win32"
346 \t\t\tOutputDirectory=""
347 \t\t\tIntermediateDirectory=""
348 \t\t\tConfigurationType="0"
350 \t\t\tATLMinimizesCRunTimeLibraryUsage="FALSE">
352 \t\t\t\tName="VCNMakeTool"
353 \t\t\t\tBuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct "Test.exe""
354 \t\t\t\tCleanCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct -c "Test.exe""
355 \t\t\t\tRebuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct "Test.exe""
356 \t\t\t\tOutput="Test.exe"/>
363 \t\t\tName="Header Files"
364 \t\t\tFilter="h;hpp;hxx;hm;inl">
366 \t\t\t\tRelativePath="sdk.h">
370 \t\t\tName="Local Headers"
371 \t\t\tFilter="h;hpp;hxx;hm;inl">
373 \t\t\t\tRelativePath="test.h">
377 \t\t\tName="Other Files"
380 \t\t\t\tRelativePath="readme.txt">
384 \t\t\tName="Resource Files"
385 \t\t\tFilter="r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
387 \t\t\t\tRelativePath="test.rc">
391 \t\t\tName="Source Files"
392 \t\t\tFilter="cpp;c;cxx;l;y;def;odl;idl;hpj;bat">
394 \t\t\t\tRelativePath="test1.cpp">
397 \t\t\t\tRelativePath="test2.cpp">
401 \t\t\tRelativePath="<SCONSCRIPT>">
406 </VisualStudioProject>
409 SConscript_contents_7_1 = """\
410 env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='7.1')
412 testsrc = ['test1.cpp', 'test2.cpp']
414 testlocalincs = ['test.h']
415 testresources = ['test.rc']
416 testmisc = ['readme.txt']
418 env.MSVSProject(target = 'Test.vcproj',
419 slnguid = '{SLNGUID}',
422 localincs = testlocalincs,
423 resources = testresources,
425 buildtarget = 'Test.exe',
431 expected_slnfile_8_0 = """\
432 Microsoft Visual Studio Solution File, Format Version 9.00
434 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{E5466E26-0003-F18B-8F8A-BCD76C86388D}"
437 \tGlobalSection(SolutionConfigurationPlatforms) = preSolution
438 \t\tRelease|Win32 = Release|Win32
440 \tGlobalSection(ProjectConfigurationPlatforms) = postSolution
441 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release|Win32.ActiveCfg = Release|Win32
442 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release|Win32.Build.0 = Release|Win32
444 \tGlobalSection(SolutionProperties) = preSolution
445 \t\tHideSolutionNode = FALSE
450 expected_vcprojfile_8_0 = """\
451 <?xml version="1.0" encoding="Windows-1252"?>
453 \tProjectType="Visual C++"
456 \tProjectGUID="<PROJECT_GUID>"
459 \tRootNamespace="Test"
460 \tKeyword="MakeFileProj">
469 \t\t\tName="Release|Win32"
470 \t\t\tConfigurationType="0"
472 \t\t\tATLMinimizesCRunTimeLibraryUsage="false"
475 \t\t\t\tName="VCNMakeTool"
476 \t\t\t\tBuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct "Test.exe""
477 \t\t\t\tReBuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct "Test.exe""
478 \t\t\t\tCleanCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct -c "Test.exe""
479 \t\t\t\tOutput="Test.exe"
480 \t\t\t\tPreprocessorDefinitions="DEF1;DEF2;DEF3=1234"
481 \t\t\t\tIncludeSearchPath="inc1;inc2"
482 \t\t\t\tForcedIncludes=""
483 \t\t\t\tAssemblySearchPath=""
484 \t\t\t\tForcedUsingAssemblies=""
485 \t\t\t\tCompileAsManaged=""
493 \t\t\tName="Header Files"
494 \t\t\tFilter="h;hpp;hxx;hm;inl">
496 \t\t\t\tRelativePath="sdk.h">
500 \t\t\tName="Local Headers"
501 \t\t\tFilter="h;hpp;hxx;hm;inl">
503 \t\t\t\tRelativePath="test.h">
507 \t\t\tName="Other Files"
510 \t\t\t\tRelativePath="readme.txt">
514 \t\t\tName="Resource Files"
515 \t\t\tFilter="r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
517 \t\t\t\tRelativePath="test.rc">
521 \t\t\tName="Source Files"
522 \t\t\tFilter="cpp;c;cxx;l;y;def;odl;idl;hpj;bat">
524 \t\t\t\tRelativePath="test1.cpp">
527 \t\t\t\tRelativePath="test2.cpp">
531 \t\t\tRelativePath="<SCONSCRIPT>">
536 </VisualStudioProject>
539 SConscript_contents_8_0 = """\
540 env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='8.0',
541 CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
542 CPPPATH=['inc1', 'inc2'])
544 testsrc = ['test1.cpp', 'test2.cpp']
546 testlocalincs = ['test.h']
547 testresources = ['test.rc']
548 testmisc = ['readme.txt']
550 env.MSVSProject(target = 'Test.vcproj',
551 slnguid = '{SLNGUID}',
554 localincs = testlocalincs,
555 resources = testresources,
557 buildtarget = 'Test.exe',
563 class TestSConsMSVS(TestSCons):
564 """Subclass for testing MSVS-specific portions of SCons."""
566 def msvs_versions(self):
567 if not hasattr(self, '_msvs_versions'):
569 # Determine the SCons version and the versions of the MSVS
570 # environments installed on the test machine.
572 # We do this by executing SCons with an SConstruct file
573 # (piped on stdin) that spits out Python assignments that
574 # we can just exec(). We construct the SCons.__"version"__
575 # string in the input here so that the SCons build itself
576 # doesn't fill it in when packaging SCons.
579 import SCons.Tool.MSCommon
580 print "self.scons_version =", repr(SCons.__%s__)
581 print "self._msvs_versions =", str(SCons.Tool.MSCommon.query_versions())
584 self.run(arguments = '-n -q -Q -f -', stdin = input)
587 return self._msvs_versions
589 def vcproj_sys_path(self, fname):
592 orig = 'sys.path = [ join(sys'
594 enginepath = repr(os.path.join(self._cwd, '..', 'engine'))
595 replace = 'sys.path = [ %s, join(sys' % enginepath
597 contents = self.read(fname)
598 contents = contents.replace(orig, replace)
599 self.write(fname, contents)
601 def msvs_substitute(self, input, msvs_ver,
602 subdir=None, sconscript=None,
605 if not hasattr(self, '_msvs_versions'):
609 workpath = self.workpath(subdir)
611 workpath = self.workpath()
613 if sconscript is None:
614 sconscript = self.workpath('SConstruct')
617 python = sys.executable
619 if project_guid is None:
620 project_guid = "{E5466E26-0003-F18B-8F8A-BCD76C86388D}"
622 if 'SCONS_LIB_DIR' in os.environ:
623 exec_script_main = "from os.path import join; import sys; sys.path = [ r'%s' ] + sys.path; import SCons.Script; SCons.Script.main()" % os.environ['SCONS_LIB_DIR']
625 exec_script_main = "from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-%s'), join(sys.prefix, 'scons-%s'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons') ] + sys.path; import SCons.Script; SCons.Script.main()" % (self.scons_version, self.scons_version)
626 exec_script_main_xml = exec_script_main.replace("'", "'")
628 result = input.replace(r'<WORKPATH>', workpath)
629 result = result.replace(r'<PYTHON>', python)
630 result = result.replace(r'<SCONSCRIPT>', sconscript)
631 result = result.replace(r'<SCONS_SCRIPT_MAIN>', exec_script_main)
632 result = result.replace(r'<SCONS_SCRIPT_MAIN_XML>', exec_script_main_xml)
633 result = result.replace(r'<PROJECT_GUID>', project_guid)
636 def get_msvs_executable(self, version):
637 """Returns a full path to the executable (MSDEV or devenv)
638 for the specified version of Visual Studio.
640 from SCons.Tool.MSCommon import get_vs_by_version
642 msvs = get_vs_by_version(version)
645 return msvs.get_executable()
647 def run(self, *args, **kw):
649 Suppress MSVS deprecation warnings.
651 save_sconsflags = os.environ.get('SCONSFLAGS')
653 sconsflags = [save_sconsflags]
656 sconsflags = sconsflags + ['--warn=no-deprecated']
657 os.environ['SCONSFLAGS'] = ' '.join(sconsflags)
659 result = TestSCons.run(self, *args, **kw)
661 os.environ['SCONSFLAGS'] = save_sconsflags or ''
666 # indent-tabs-mode:nil
668 # vim: set expandtab tabstop=4 shiftwidth=4: