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__"
24 from TestSCons import *
25 from TestSCons import __all__
29 expected_dspfile_6_0 = '''\
30 # Microsoft Developer Studio Project File - Name="Test" - Package Owner=<4>
31 # Microsoft Developer Studio Generated Build File, Format Version 6.00
34 # TARGTYPE "Win32 (x86) External Target" 0x0106
36 CFG=Test - Win32 Release
37 !MESSAGE This is not a valid makefile. To build this project using NMAKE,
38 !MESSAGE use the Export Makefile command and run
40 !MESSAGE NMAKE /f "Test.mak".
42 !MESSAGE You can specify a configuration when running NMAKE
43 !MESSAGE by defining the macro CFG on the command line. For example:
45 !MESSAGE NMAKE /f "Test.mak" CFG="Test - Win32 Release"
47 !MESSAGE Possible choices for configuration are:
49 !MESSAGE "Test - Win32 Release" (based on "Win32 (x86) External Target")
53 # PROP AllowPerConfigDependencies 0
54 # PROP Scc_ProjName ""
55 # PROP Scc_LocalPath ""
57 !IF "$(CFG)" == "Test - Win32 Release"
60 # PROP BASE Use_Debug_Libraries 0
61 # PROP BASE Output_Dir ""
62 # PROP BASE Intermediate_Dir ""
63 # PROP BASE Cmd_Line "echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
64 # PROP BASE Rebuild_Opt "-c && echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
65 # PROP BASE Target_File "Test.exe"
66 # PROP BASE Bsc_Name ""
67 # PROP BASE Target_Dir ""
69 # PROP Use_Debug_Libraries 0
71 # PROP Intermediate_Dir ""
72 # PROP Cmd_Line "echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
73 # PROP Rebuild_Opt "-c && echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
74 # PROP Target_File "Test.exe"
82 # Name "Test - Win32 Release"
84 !IF "$(CFG)" == "Test - Win32 Release"
88 # Begin Group "Header Files"
90 # PROP Default_Filter "h;hpp;hxx;hm;inl"
96 # Begin Group "Local Headers"
98 # PROP Default_Filter "h;hpp;hxx;hm;inl"
104 # Begin Group "Other Files"
106 # PROP Default_Filter ""
112 # Begin Group "Resource Files"
114 # PROP Default_Filter "r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
120 # Begin Group "Source Files"
122 # PROP Default_Filter "cpp;c;cxx;l;y;def;odl;idl;hpj;bat"
130 SOURCE="<SCONSCRIPT>"
136 expected_dswfile_6_0 = '''\
137 Microsoft Developer Studio Workspace File, Format Version 6.00
138 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
140 ###############################################################################
142 Project: "Test"="Test.dsp" - Package Owner=<4>
152 ###############################################################################
164 ###############################################################################
167 SConscript_contents_6_0 = """\
168 env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='6.0')
172 testlocalincs = ['test.h']
173 testresources = ['test.rc']
174 testmisc = ['readme.txt']
176 env.MSVSProject(target = 'Test.dsp',
179 localincs = testlocalincs,
180 resources = testresources,
182 buildtarget = 'Test.exe',
188 expected_slnfile_7_0 = """\
189 Microsoft Visual Studio Solution File, Format Version 7.00
190 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{E5466E26-0003-F18B-8F8A-BCD76C86388D}"
193 \tGlobalSection(SolutionConfiguration) = preSolution
194 \t\tConfigName.0 = Release
196 \tGlobalSection(ProjectDependencies) = postSolution
198 \tGlobalSection(ProjectConfiguration) = postSolution
199 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release.ActiveCfg = Release|Win32
200 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release.Build.0 = Release|Win32
202 \tGlobalSection(ExtensibilityGlobals) = postSolution
204 \tGlobalSection(ExtensibilityAddIns) = postSolution
209 expected_vcprojfile_7_0 = """\
210 <?xml version="1.0" encoding = "Windows-1252"?>
212 \tProjectType="Visual C++"
218 \tKeyword="MakeFileProj">
225 \t\t\tName="Release|Win32"
226 \t\t\tOutputDirectory=""
227 \t\t\tIntermediateDirectory=""
228 \t\t\tConfigurationType="0"
230 \t\t\tATLMinimizesCRunTimeLibraryUsage="FALSE">
232 \t\t\t\tName="VCNMakeTool"
233 \t\t\t\tBuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct "Test.exe""
234 \t\t\t\tCleanCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct -c "Test.exe""
235 \t\t\t\tRebuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct "Test.exe""
236 \t\t\t\tOutput="Test.exe"/>
241 \t\t\tName="Header Files"
242 \t\t\tFilter="h;hpp;hxx;hm;inl">
244 \t\t\t\tRelativePath="sdk.h">
248 \t\t\tName="Local Headers"
249 \t\t\tFilter="h;hpp;hxx;hm;inl">
251 \t\t\t\tRelativePath="test.h">
255 \t\t\tName="Other Files"
258 \t\t\t\tRelativePath="readme.txt">
262 \t\t\tName="Resource Files"
263 \t\t\tFilter="r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
265 \t\t\t\tRelativePath="test.rc">
269 \t\t\tName="Source Files"
270 \t\t\tFilter="cpp;c;cxx;l;y;def;odl;idl;hpj;bat">
272 \t\t\t\tRelativePath="test1.cpp">
275 \t\t\t\tRelativePath="test2.cpp">
279 \t\t\tRelativePath="<SCONSCRIPT>">
284 </VisualStudioProject>
287 SConscript_contents_7_0 = """\
288 env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='7.0')
290 testsrc = ['test1.cpp', 'test2.cpp']
292 testlocalincs = ['test.h']
293 testresources = ['test.rc']
294 testmisc = ['readme.txt']
296 env.MSVSProject(target = 'Test.vcproj',
297 slnguid = '{SLNGUID}',
300 localincs = testlocalincs,
301 resources = testresources,
303 buildtarget = 'Test.exe',
309 expected_slnfile_7_1 = """\
310 Microsoft Visual Studio Solution File, Format Version 8.00
311 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{E5466E26-0003-F18B-8F8A-BCD76C86388D}"
312 \tProjectSection(ProjectDependencies) = postProject
316 \tGlobalSection(SolutionConfiguration) = preSolution
317 \t\tConfigName.0 = Release
319 \tGlobalSection(ProjectConfiguration) = postSolution
320 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release.ActiveCfg = Release|Win32
321 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release.Build.0 = Release|Win32
323 \tGlobalSection(ExtensibilityGlobals) = postSolution
325 \tGlobalSection(ExtensibilityAddIns) = postSolution
330 expected_vcprojfile_7_1 = """\
331 <?xml version="1.0" encoding = "Windows-1252"?>
333 \tProjectType="Visual C++"
339 \tKeyword="MakeFileProj">
346 \t\t\tName="Release|Win32"
347 \t\t\tOutputDirectory=""
348 \t\t\tIntermediateDirectory=""
349 \t\t\tConfigurationType="0"
351 \t\t\tATLMinimizesCRunTimeLibraryUsage="FALSE">
353 \t\t\t\tName="VCNMakeTool"
354 \t\t\t\tBuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct "Test.exe""
355 \t\t\t\tCleanCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct -c "Test.exe""
356 \t\t\t\tRebuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct "Test.exe""
357 \t\t\t\tOutput="Test.exe"/>
364 \t\t\tName="Header Files"
365 \t\t\tFilter="h;hpp;hxx;hm;inl">
367 \t\t\t\tRelativePath="sdk.h">
371 \t\t\tName="Local Headers"
372 \t\t\tFilter="h;hpp;hxx;hm;inl">
374 \t\t\t\tRelativePath="test.h">
378 \t\t\tName="Other Files"
381 \t\t\t\tRelativePath="readme.txt">
385 \t\t\tName="Resource Files"
386 \t\t\tFilter="r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
388 \t\t\t\tRelativePath="test.rc">
392 \t\t\tName="Source Files"
393 \t\t\tFilter="cpp;c;cxx;l;y;def;odl;idl;hpj;bat">
395 \t\t\t\tRelativePath="test1.cpp">
398 \t\t\t\tRelativePath="test2.cpp">
402 \t\t\tRelativePath="<SCONSCRIPT>">
407 </VisualStudioProject>
410 SConscript_contents_7_1 = """\
411 env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='7.1')
413 testsrc = ['test1.cpp', 'test2.cpp']
415 testlocalincs = ['test.h']
416 testresources = ['test.rc']
417 testmisc = ['readme.txt']
419 env.MSVSProject(target = 'Test.vcproj',
420 slnguid = '{SLNGUID}',
423 localincs = testlocalincs,
424 resources = testresources,
426 buildtarget = 'Test.exe',
432 expected_slnfile_8_0 = """\
433 Microsoft Visual Studio Solution File, Format Version 9.00
435 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{E5466E26-0003-F18B-8F8A-BCD76C86388D}"
438 \tGlobalSection(SolutionConfigurationPlatforms) = preSolution
439 \t\tRelease|Win32 = Release|Win32
441 \tGlobalSection(ProjectConfigurationPlatforms) = postSolution
442 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release|Win32.ActiveCfg = Release|Win32
443 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release|Win32.Build.0 = Release|Win32
445 \tGlobalSection(SolutionProperties) = preSolution
446 \t\tHideSolutionNode = FALSE
451 expected_vcprojfile_8_0 = """\
452 <?xml version="1.0" encoding="Windows-1252"?>
454 \tProjectType="Visual C++"
457 \tProjectGUID="<PROJECT_GUID>"
460 \tRootNamespace="Test"
461 \tKeyword="MakeFileProj">
470 \t\t\tName="Release|Win32"
471 \t\t\tConfigurationType="0"
473 \t\t\tATLMinimizesCRunTimeLibraryUsage="false"
476 \t\t\t\tName="VCNMakeTool"
477 \t\t\t\tBuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct "Test.exe""
478 \t\t\t\tReBuildCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct "Test.exe""
479 \t\t\t\tCleanCommandLine="echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN_XML>" -C "<WORKPATH>" -f SConstruct -c "Test.exe""
480 \t\t\t\tOutput="Test.exe"
481 \t\t\t\tPreprocessorDefinitions=""
482 \t\t\t\tIncludeSearchPath=""
483 \t\t\t\tForcedIncludes=""
484 \t\t\t\tAssemblySearchPath=""
485 \t\t\t\tForcedUsingAssemblies=""
486 \t\t\t\tCompileAsManaged=""
494 \t\t\tName="Header Files"
495 \t\t\tFilter="h;hpp;hxx;hm;inl">
497 \t\t\t\tRelativePath="sdk.h">
501 \t\t\tName="Local Headers"
502 \t\t\tFilter="h;hpp;hxx;hm;inl">
504 \t\t\t\tRelativePath="test.h">
508 \t\t\tName="Other Files"
511 \t\t\t\tRelativePath="readme.txt">
515 \t\t\tName="Resource Files"
516 \t\t\tFilter="r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
518 \t\t\t\tRelativePath="test.rc">
522 \t\t\tName="Source Files"
523 \t\t\tFilter="cpp;c;cxx;l;y;def;odl;idl;hpj;bat">
525 \t\t\t\tRelativePath="test1.cpp">
528 \t\t\t\tRelativePath="test2.cpp">
532 \t\t\tRelativePath="<SCONSCRIPT>">
537 </VisualStudioProject>
540 SConscript_contents_8_0 = """\
541 env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='8.0')
543 testsrc = ['test1.cpp', 'test2.cpp']
545 testlocalincs = ['test.h']
546 testresources = ['test.rc']
547 testmisc = ['readme.txt']
549 env.MSVSProject(target = 'Test.vcproj',
550 slnguid = '{SLNGUID}',
553 localincs = testlocalincs,
554 resources = testresources,
556 buildtarget = 'Test.exe',
562 class TestSConsMSVS(TestSCons):
563 """Subclass for testing MSVS-specific portions of SCons."""
565 def msvs_versions(self):
566 if not hasattr(self, '_msvs_versions'):
568 # Determine the SCons version and the versions of the MSVS
569 # environments installed on the test machine.
571 # We do this by executing SCons with an SConstruct file
572 # (piped on stdin) that spits out Python assignments that
573 # we can just exec(). We construct the SCons.__"version"__
574 # string in the input here so that the SCons build itself
575 # doesn't fill it in when packaging SCons.
578 print "self.scons_version =", repr(SCons.__%s__)
580 print "self._msvs_versions =", str(env['MSVS']['VERSIONS'])
583 self.run(arguments = '-n -q -Q -f -', stdin = input)
586 return self._msvs_versions
588 def vcproj_sys_path(self, fname):
591 orig = 'sys.path = [ join(sys'
593 enginepath = repr(os.path.join(self._cwd, '..', 'engine'))
594 replace = 'sys.path = [ %s, join(sys' % enginepath
596 contents = self.read(fname)
597 contents = string.replace(contents, orig, replace)
598 self.write(fname, contents)
600 def msvs_substitute(self, input, msvs_ver,
601 subdir=None, sconscript=None,
604 if not hasattr(self, '_msvs_versions'):
608 workpath = self.workpath(subdir)
610 workpath = self.workpath()
612 if sconscript is None:
613 sconscript = self.workpath('SConstruct')
616 python = sys.executable
618 if project_guid is None:
619 project_guid = "{E5466E26-0003-F18B-8F8A-BCD76C86388D}"
621 if os.environ.has_key('SCONS_LIB_DIR'):
622 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']
624 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)
625 exec_script_main_xml = string.replace(exec_script_main, "'", "'")
627 result = string.replace(input, r'<WORKPATH>', workpath)
628 result = string.replace(result, r'<PYTHON>', python)
629 result = string.replace(result, r'<SCONSCRIPT>', sconscript)
630 result = string.replace(result, r'<SCONS_SCRIPT_MAIN>', exec_script_main)
631 result = string.replace(result, r'<SCONS_SCRIPT_MAIN_XML>', exec_script_main_xml)
632 result = string.replace(result, r'<PROJECT_GUID>', project_guid)
635 def get_msvs_executable(self, version):
636 """Returns a full path to the executable (MSDEV or devenv)
637 for the specified version of Visual Studio.
639 common_msdev98_bin_msdev_com = ['Common', 'MSDev98', 'Bin', 'MSDEV.COM']
640 common7_ide_devenv_com = ['Common7', 'IDE', 'devenv.com']
641 common7_ide_vcexpress_exe = ['Common7', 'IDE', 'VCExpress.exe']
644 common_msdev98_bin_msdev_com,
647 common7_ide_devenv_com,
650 common7_ide_devenv_com,
653 common7_ide_devenv_com,
654 common7_ide_vcexpress_exe,
657 from SCons.Tool.msvs import get_msvs_install_dirs
658 vs_path = get_msvs_install_dirs(version)['VSINSTALLDIR']
659 for sp in sub_paths[version]:
660 p = apply(os.path.join, [vs_path] + sp)
661 if os.path.exists(p):
663 return apply(os.path.join, [vs_path] + sub_paths[version][0])