[ci skip] update generated files
[scons.git] / test / MSVS / common-prefix.py
blob070ce0d0e4a727c8620988ea3ee088c0deffec4f
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 project_guid = TestSConsMSVS.PROJECT_GUID
43 vcproj_template = """\
44 <?xml version="1.0" encoding="Windows-1252"?>
45 <VisualStudioProject
46 \tProjectType="Visual C++"
47 \tVersion="8.00"
48 \tName="Test"
49 \tProjectGUID="<PROJECT_GUID>"
50 \tRootNamespace="Test"
51 \tKeyword="MakeFileProj">
52 \t<Platforms>
53 \t\t<Platform
54 \t\t\tName="Win32"/>
55 \t</Platforms>
56 \t<ToolFiles>
57 \t</ToolFiles>
58 \t<Configurations>
59 \t\t<Configuration
60 \t\t\tName="Release|Win32"
61 \t\t\tConfigurationType="0"
62 \t\t\tUseOfMFC="0"
63 \t\t\tATLMinimizesCRunTimeLibraryUsage="false"
64 \t\t\t>
65 \t\t\t<Tool
66 \t\t\t\tName="VCNMakeTool"
67 \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;"
68 \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;"
69 \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;"
70 \t\t\t\tOutput="Test.exe"
71 \t\t\t\tPreprocessorDefinitions=""
72 \t\t\t\tIncludeSearchPath=""
73 \t\t\t\tForcedIncludes=""
74 \t\t\t\tAssemblySearchPath=""
75 \t\t\t\tForcedUsingAssemblies=""
76 \t\t\t\tCompileAsManaged=""
77 \t\t\t/>
78 \t\t</Configuration>
79 \t</Configurations>
80 \t<References>
81 \t</References>
82 %(sln_files)s
83 \t<Globals>
84 \t</Globals>
85 </VisualStudioProject>
86 """
88 SConscript_contents = """\
89 env=Environment(tools=['msvs'], MSVS_VERSION = '8.0')
91 testsrc = %(testsrc)s
93 env.MSVSProject(target = 'Test.vcproj',
94 MSVS_PROJECT_GUID = '%(project_guid)s',
95 slnguid = '{SLNGUID}',
96 srcs = testsrc,
97 buildtarget = 'Test.exe',
98 variant = 'Release',
99 auto_build_solution = 0)
102 test.subdir('work1')
104 testsrc = repr([
105 'prefix/subdir1/test1.cpp',
106 r'prefix\subdir1\test2.cpp',
107 'prefix/subdir2/test3.cpp',
110 sln_files = """\t<Files>
111 \t\t\t<Filter
112 \t\t\t\tName="subdir1"
113 \t\t\t\tFilter="">
114 \t\t\t<File
115 \t\t\t\tRelativePath="prefix\\subdir1\\test1.cpp">
116 \t\t\t</File>
117 \t\t\t<File
118 \t\t\t\tRelativePath="prefix\\subdir1\\test2.cpp">
119 \t\t\t</File>
120 \t\t\t</Filter>
121 \t\t\t<Filter
122 \t\t\t\tName="subdir2"
123 \t\t\t\tFilter="">
124 \t\t\t<File
125 \t\t\t\tRelativePath="prefix\\subdir2\\test3.cpp">
126 \t\t\t</File>
127 \t\t\t</Filter>
128 \t\t<File
129 \t\t\tRelativePath="<SCONSCRIPT>">
130 \t\t</File>
131 \t</Files>"""
133 test.write(['work1', 'SConstruct'], SConscript_contents % locals())
135 test.run(chdir='work1', arguments="Test.vcproj")
137 test.must_exist(test.workpath('work1', 'Test.vcproj'))
138 vcproj = test.read(['work1', 'Test.vcproj'], 'r')
139 expected_vcprojfile = vcproj_template % locals()
140 expect = test.msvs_substitute(expected_vcprojfile, '8.0', 'work1', 'SConstruct')
141 # don't compare the pickled data
142 assert vcproj[:len(expect)] == expect, test.diff_substr(expect, vcproj)
144 test.subdir('work2')
146 testsrc = repr([
147 'prefix/subdir/somefile.cpp',
150 sln_files = """\t<Files>
151 \t\t\t<File
152 \t\t\t\tRelativePath="prefix\\subdir\\somefile.cpp">
153 \t\t\t</File>
154 \t\t<File
155 \t\t\tRelativePath="<SCONSCRIPT>">
156 \t\t</File>
157 \t</Files>"""
159 test.write(['work2', 'SConstruct'], SConscript_contents % locals())
161 test.run(chdir='work2', arguments="Test.vcproj")
163 test.must_exist(test.workpath('work2', 'Test.vcproj'))
164 vcproj = test.read(['work2', 'Test.vcproj'], 'r')
165 expected_vcprojfile = vcproj_template % locals()
166 expect = test.msvs_substitute(expected_vcprojfile, '8.0', 'work2', 'SConstruct')
167 # don't compare the pickled data
168 assert vcproj[:len(expect)] == expect, test.diff_substr(expect, vcproj)
170 test.pass_test()
172 # Local Variables:
173 # tab-width:4
174 # indent-tabs-mode:nil
175 # End:
176 # vim: set expandtab tabstop=4 shiftwidth=4: