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