Merge pull request #4584 from siegria/fix_piped_spawn_encoding
[scons.git] / test / MSVS / common-prefix.py
blobea95c032a040c7c4923b788408cd8f4041629b65
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Test that we can generate Visual Studio 8.0 project (.vcproj) and
28 solution (.sln) files that look correct.
29 """
31 import sys
33 import TestSConsMSVS
35 test = TestSConsMSVS.TestSConsMSVS()
37 if sys.platform != 'win32':
38 msg = "Skipping Visual Studio test on non-Windows platform '%s'\n" % sys.platform
39 test.skip_test(msg)
41 vcproj_template = """\
42 <?xml version="1.0" encoding="Windows-1252"?>
43 <VisualStudioProject
44 \tProjectType="Visual C++"
45 \tVersion="8.00"
46 \tName="Test"
47 \tProjectGUID="<PROJECT_GUID>"
48 \tRootNamespace="Test"
49 \tKeyword="MakeFileProj">
50 \t<Platforms>
51 \t\t<Platform
52 \t\t\tName="Win32"/>
53 \t</Platforms>
54 \t<ToolFiles>
55 \t</ToolFiles>
56 \t<Configurations>
57 \t\t<Configuration
58 \t\t\tName="Release|Win32"
59 \t\t\tConfigurationType="0"
60 \t\t\tUseOfMFC="0"
61 \t\t\tATLMinimizesCRunTimeLibraryUsage="false"
62 \t\t\t>
63 \t\t\t<Tool
64 \t\t\t\tName="VCNMakeTool"
65 \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 &quot;Test.exe&quot;"
66 \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 &quot;Test.exe&quot;"
67 \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 &quot;Test.exe&quot;"
68 \t\t\t\tOutput="Test.exe"
69 \t\t\t\tPreprocessorDefinitions=""
70 \t\t\t\tIncludeSearchPath=""
71 \t\t\t\tForcedIncludes=""
72 \t\t\t\tAssemblySearchPath=""
73 \t\t\t\tForcedUsingAssemblies=""
74 \t\t\t\tCompileAsManaged=""
75 \t\t\t/>
76 \t\t</Configuration>
77 \t</Configurations>
78 \t<References>
79 \t</References>
80 %(sln_files)s
81 \t<Globals>
82 \t</Globals>
83 </VisualStudioProject>
84 """
88 SConscript_contents = """\
89 env=Environment(tools=['msvs'], MSVS_VERSION = '8.0')
91 testsrc = %(testsrc)s
93 env.MSVSProject(target = 'Test.vcproj',
94 slnguid = '{SLNGUID}',
95 srcs = testsrc,
96 buildtarget = 'Test.exe',
97 variant = 'Release',
98 auto_build_solution = 0)
99 """
103 test.subdir('work1')
105 testsrc = repr([
106 'prefix/subdir1/test1.cpp',
107 r'prefix\subdir1\test2.cpp',
108 'prefix/subdir2/test3.cpp',
111 sln_files = """\t<Files>
112 \t\t\t<Filter
113 \t\t\t\tName="subdir1"
114 \t\t\t\tFilter="">
115 \t\t\t<File
116 \t\t\t\tRelativePath="prefix\\subdir1\\test1.cpp">
117 \t\t\t</File>
118 \t\t\t<File
119 \t\t\t\tRelativePath="prefix\\subdir1\\test2.cpp">
120 \t\t\t</File>
121 \t\t\t</Filter>
122 \t\t\t<Filter
123 \t\t\t\tName="subdir2"
124 \t\t\t\tFilter="">
125 \t\t\t<File
126 \t\t\t\tRelativePath="prefix\\subdir2\\test3.cpp">
127 \t\t\t</File>
128 \t\t\t</Filter>
129 \t\t<File
130 \t\t\tRelativePath="<SCONSCRIPT>">
131 \t\t</File>
132 \t</Files>"""
134 test.write(['work1', 'SConstruct'], SConscript_contents % locals())
136 test.run(chdir='work1', arguments="Test.vcproj")
138 test.must_exist(test.workpath('work1', 'Test.vcproj'))
139 vcproj = test.read(['work1', 'Test.vcproj'], 'r')
140 expected_vcprojfile = vcproj_template % locals()
141 expect = test.msvs_substitute(expected_vcprojfile, '8.0', 'work1', 'SConstruct')
142 # don't compare the pickled data
143 assert vcproj[:len(expect)] == expect, test.diff_substr(expect, vcproj)
147 test.subdir('work2')
149 testsrc = repr([
150 'prefix/subdir/somefile.cpp',
153 sln_files = """\t<Files>
154 \t\t\t<File
155 \t\t\t\tRelativePath="prefix\\subdir\\somefile.cpp">
156 \t\t\t</File>
157 \t\t<File
158 \t\t\tRelativePath="<SCONSCRIPT>">
159 \t\t</File>
160 \t</Files>"""
162 test.write(['work2', 'SConstruct'], SConscript_contents % locals())
164 test.run(chdir='work2', arguments="Test.vcproj")
166 test.must_exist(test.workpath('work2', 'Test.vcproj'))
167 vcproj = test.read(['work2', 'Test.vcproj'], 'r')
168 expected_vcprojfile = vcproj_template % locals()
169 expect = test.msvs_substitute(expected_vcprojfile, '8.0', 'work2', 'SConstruct')
170 # don't compare the pickled data
171 assert vcproj[:len(expect)] == expect, test.diff_substr(expect, vcproj)
175 test.pass_test()
177 # Local Variables:
178 # tab-width:4
179 # indent-tabs-mode:nil
180 # End:
181 # vim: set expandtab tabstop=4 shiftwidth=4: