""" TestSConsMSVS.py: a testing framework for the SCons software construction tool. A TestSConsMSVS environment object is created via the usual invocation: test = TestSConsMSVS() TestSConsMSVS is a subsclass of TestSCons, which is in turn a subclass of TestCommon, which is in turn is a subclass of TestCmd), and hence has available all of the methods and attributes from those classes, as well as any overridden or additional methods or attributes defined in this subclass. """ # __COPYRIGHT__ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import os import string import sys from TestSCons import * from TestSCons import __all__ expected_dspfile_6_0 = '''\ # Microsoft Developer Studio Project File - Name="Test" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) External Target" 0x0106 CFG=Test - Win32 Release !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "Test.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "Test.mak" CFG="Test - Win32 Release" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "Test - Win32 Release" (based on "Win32 (x86) External Target") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" !IF "$(CFG)" == "Test - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "" # PROP BASE Intermediate_Dir "" # PROP BASE Cmd_Line "echo Starting SCons && "" -c "" -C "" -f SConstruct "Test.exe"" # PROP BASE Rebuild_Opt "-c && echo Starting SCons && "" -c "" -C "" -f SConstruct "Test.exe"" # PROP BASE Target_File "Test.exe" # PROP BASE Bsc_Name "" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "" # PROP Intermediate_Dir "" # PROP Cmd_Line "echo Starting SCons && "" -c "" -C "" -f SConstruct "Test.exe"" # PROP Rebuild_Opt "-c && echo Starting SCons && "" -c "" -C "" -f SConstruct "Test.exe"" # PROP Target_File "Test.exe" # PROP Bsc_Name "" # PROP Target_Dir "" !ENDIF # Begin Target # Name "Test - Win32 Release" !IF "$(CFG)" == "Test - Win32 Release" !ENDIF # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Source File SOURCE="sdk.h" # End Source File # End Group # Begin Group "Local Headers" # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Source File SOURCE="test.h" # End Source File # End Group # Begin Group "Other Files" # PROP Default_Filter "" # Begin Source File SOURCE="readme.txt" # End Source File # End Group # Begin Group "Resource Files" # PROP Default_Filter "r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" # Begin Source File SOURCE="test.rc" # End Source File # End Group # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;l;y;def;odl;idl;hpj;bat" # Begin Source File SOURCE="test.c" # End Source File # End Group # Begin Source File SOURCE="" # End Source File # End Target # End Project ''' expected_dswfile_6_0 = '''\ Microsoft Developer Studio Workspace File, Format Version 6.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "Test"="Test.dsp" - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### ''' SConscript_contents_6_0 = """\ env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='6.0') testsrc = ['test.c'] testincs = ['sdk.h'] testlocalincs = ['test.h'] testresources = ['test.rc'] testmisc = ['readme.txt'] env.MSVSProject(target = 'Test.dsp', srcs = testsrc, incs = testincs, localincs = testlocalincs, resources = testresources, misc = testmisc, buildtarget = 'Test.exe', variant = 'Release') """ expected_slnfile_7_0 = """\ Microsoft Visual Studio Solution File, Format Version 7.00 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{E5466E26-0003-F18B-8F8A-BCD76C86388D}" EndProject Global \tGlobalSection(SolutionConfiguration) = preSolution \t\tConfigName.0 = Release \tEndGlobalSection \tGlobalSection(ProjectDependencies) = postSolution \tEndGlobalSection \tGlobalSection(ProjectConfiguration) = postSolution \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release.ActiveCfg = Release|Win32 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release.Build.0 = Release|Win32 \tEndGlobalSection \tGlobalSection(ExtensibilityGlobals) = postSolution \tEndGlobalSection \tGlobalSection(ExtensibilityAddIns) = postSolution \tEndGlobalSection EndGlobal """ expected_vcprojfile_7_0 = """\ \t \t\t \t \t \t\t \t\t\t \t\t \t \t \t\t \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t \t\t \t\t \t \t \t """ SConscript_contents_7_0 = """\ env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='7.0') testsrc = ['test1.cpp', 'test2.cpp'] testincs = ['sdk.h'] testlocalincs = ['test.h'] testresources = ['test.rc'] testmisc = ['readme.txt'] env.MSVSProject(target = 'Test.vcproj', slnguid = '{SLNGUID}', srcs = testsrc, incs = testincs, localincs = testlocalincs, resources = testresources, misc = testmisc, buildtarget = 'Test.exe', variant = 'Release') """ expected_slnfile_7_1 = """\ Microsoft Visual Studio Solution File, Format Version 8.00 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{E5466E26-0003-F18B-8F8A-BCD76C86388D}" \tProjectSection(ProjectDependencies) = postProject \tEndProjectSection EndProject Global \tGlobalSection(SolutionConfiguration) = preSolution \t\tConfigName.0 = Release \tEndGlobalSection \tGlobalSection(ProjectConfiguration) = postSolution \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release.ActiveCfg = Release|Win32 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release.Build.0 = Release|Win32 \tEndGlobalSection \tGlobalSection(ExtensibilityGlobals) = postSolution \tEndGlobalSection \tGlobalSection(ExtensibilityAddIns) = postSolution \tEndGlobalSection EndGlobal """ expected_vcprojfile_7_1 = """\ \t \t\t \t \t \t\t \t\t\t \t\t \t \t \t \t \t\t \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t \t\t \t\t \t \t \t """ SConscript_contents_7_1 = """\ env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='7.1') testsrc = ['test1.cpp', 'test2.cpp'] testincs = ['sdk.h'] testlocalincs = ['test.h'] testresources = ['test.rc'] testmisc = ['readme.txt'] env.MSVSProject(target = 'Test.vcproj', slnguid = '{SLNGUID}', srcs = testsrc, incs = testincs, localincs = testlocalincs, resources = testresources, misc = testmisc, buildtarget = 'Test.exe', variant = 'Release') """ expected_slnfile_8_0 = """\ Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "{E5466E26-0003-F18B-8F8A-BCD76C86388D}" EndProject Global \tGlobalSection(SolutionConfigurationPlatforms) = preSolution \t\tRelease|Win32 = Release|Win32 \tEndGlobalSection \tGlobalSection(ProjectConfigurationPlatforms) = postSolution \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release|Win32.ActiveCfg = Release|Win32 \t\t{E5466E26-0003-F18B-8F8A-BCD76C86388D}.Release|Win32.Build.0 = Release|Win32 \tEndGlobalSection \tGlobalSection(SolutionProperties) = preSolution \t\tHideSolutionNode = FALSE \tEndGlobalSection EndGlobal """ expected_vcprojfile_8_0 = """\ \t \t\t \t \t \t \t \t\t \t\t\t \t\t \t \t \t \t \t\t \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t\t \t\t \t\t \t\t\t \t\t\t \t\t\t \t\t\t \t\t \t\t \t\t \t \t \t """ SConscript_contents_8_0 = """\ env=Environment(platform='win32', tools=['msvs'], MSVS_VERSION='8.0') testsrc = ['test1.cpp', 'test2.cpp'] testincs = ['sdk.h'] testlocalincs = ['test.h'] testresources = ['test.rc'] testmisc = ['readme.txt'] env.MSVSProject(target = 'Test.vcproj', slnguid = '{SLNGUID}', srcs = testsrc, incs = testincs, localincs = testlocalincs, resources = testresources, misc = testmisc, buildtarget = 'Test.exe', variant = 'Release') """ class TestSConsMSVS(TestSCons): """Subclass for testing MSVS-specific portions of SCons.""" def msvs_versions(self): if not hasattr(self, '_msvs_versions'): # Determine the SCons version and the versions of the MSVS # environments installed on the test machine. # # We do this by executing SCons with an SConstruct file # (piped on stdin) that spits out Python assignments that # we can just exec(). We construct the SCons.__"version"__ # string in the input here so that the SCons build itself # doesn't fill it in when packaging SCons. input = """\ import SCons print "self.scons_version =", repr(SCons.__%s__) env = Environment(); print "self._msvs_versions =", str(env['MSVS']['VERSIONS']) """ % 'version' self.run(arguments = '-n -q -Q -f -', stdin = input) exec(self.stdout()) return self._msvs_versions def vcproj_sys_path(self, fname): """ """ orig = 'sys.path = [ join(sys' enginepath = repr(os.path.join(self._cwd, '..', 'engine')) replace = 'sys.path = [ %s, join(sys' % enginepath contents = self.read(fname) contents = string.replace(contents, orig, replace) self.write(fname, contents) def msvs_substitute(self, input, msvs_ver, subdir=None, sconscript=None, python=None, project_guid=None): if not hasattr(self, '_msvs_versions'): self.msvs_versions() if subdir: workpath = self.workpath(subdir) else: workpath = self.workpath() if sconscript is None: sconscript = self.workpath('SConstruct') if python is None: python = sys.executable if project_guid is None: project_guid = "{E5466E26-0003-F18B-8F8A-BCD76C86388D}" if os.environ.has_key('SCONS_LIB_DIR'): 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'] else: 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) exec_script_main_xml = string.replace(exec_script_main, "'", "'") result = string.replace(input, r'', workpath) result = string.replace(result, r'', python) result = string.replace(result, r'', sconscript) result = string.replace(result, r'', exec_script_main) result = string.replace(result, r'', exec_script_main_xml) result = string.replace(result, r'', project_guid) return result def get_msvs_executable(self, version): """Returns a full path to the executable (MSDEV or devenv) for the specified version of Visual Studio. """ common_msdev98_bin_msdev_com = ['Common', 'MSDev98', 'Bin', 'MSDEV.COM'] common7_ide_devenv_com = ['Common7', 'IDE', 'devenv.com'] common7_ide_vcexpress_exe = ['Common7', 'IDE', 'VCExpress.exe'] sub_paths = { '6.0' : [ common_msdev98_bin_msdev_com, ], '7.0' : [ common7_ide_devenv_com, ], '7.1' : [ common7_ide_devenv_com, ], '8.0' : [ common7_ide_devenv_com, common7_ide_vcexpress_exe, ], } from SCons.Tool.msvs import get_msvs_install_dirs vs_path = get_msvs_install_dirs(version)['VSINSTALLDIR'] for sp in sub_paths[version]: p = apply(os.path.join, [vs_path] + sp) if os.path.exists(p): return p return apply(os.path.join, [vs_path] + sub_paths[version][0])