test framework: bulk reformat
[scons.git] / testing / framework / TestSConsMSVS.py
blob88026e141be125db45c1b750d700948144d0dc37
1 # MIT License
3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 """
25 A testing framework for the SCons software construction tool.
27 A TestSConsMSVS environment object is created via the usual invocation:
29 test = TestSConsMSVS()
31 TestSConsMSVS is a subsclass of TestSCons, which is in turn a subclass
32 of TestCommon, which is in turn is a subclass of TestCmd), and hence
33 has available all of the methods and attributes from those classes,
34 as well as any overridden or additional methods or attributes defined
35 in this subclass.
36 """
38 import os
39 import sys
40 import platform
41 import traceback
42 from xml.etree import ElementTree
44 try:
45 import winreg
46 except ImportError:
47 winreg = None
49 import SCons.Errors
50 from TestSCons import *
51 from TestSCons import __all__
54 PROJECT_GUID = "{00000000-0000-0000-0000-000000000000}"
55 PROJECT_GUID_1 = "{11111111-1111-1111-1111-111111111111}"
56 PROJECT_GUID_2 = "{22222222-2222-2222-2222-222222222222}"
58 SOLUTION_GUID_1 = "{88888888-8888-8888-8888-888888888888}"
59 SOLUTION_GUID_2 = "{99999999-9999-9999-9999-999999999999}"
61 expected_dspfile_6_0 = '''\
62 # Microsoft Developer Studio Project File - Name="Test" - Package Owner=<4>
63 # Microsoft Developer Studio Generated Build File, Format Version 6.00
64 # ** DO NOT EDIT **
66 # TARGTYPE "Win32 (x86) External Target" 0x0106
68 CFG=Test - Win32 Release
69 !MESSAGE This is not a valid makefile. To build this project using NMAKE,
70 !MESSAGE use the Export Makefile command and run
71 !MESSAGE
72 !MESSAGE NMAKE /f "Test.mak".
73 !MESSAGE
74 !MESSAGE You can specify a configuration when running NMAKE
75 !MESSAGE by defining the macro CFG on the command line. For example:
76 !MESSAGE
77 !MESSAGE NMAKE /f "Test.mak" CFG="Test - Win32 Release"
78 !MESSAGE
79 !MESSAGE Possible choices for configuration are:
80 !MESSAGE
81 !MESSAGE "Test - Win32 Release" (based on "Win32 (x86) External Target")
82 !MESSAGE
84 # Begin Project
85 # PROP AllowPerConfigDependencies 0
86 # PROP Scc_ProjName ""
87 # PROP Scc_LocalPath ""
89 !IF "$(CFG)" == "Test - Win32 Release"
91 # PROP BASE Use_MFC 0
92 # PROP BASE Use_Debug_Libraries 0
93 # PROP BASE Output_Dir ""
94 # PROP BASE Intermediate_Dir ""
95 # PROP BASE Cmd_Line "echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
96 # PROP BASE Rebuild_Opt "-c && echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
97 # PROP BASE Target_File "Test.exe"
98 # PROP BASE Bsc_Name ""
99 # PROP BASE Target_Dir ""
100 # PROP Use_MFC 0
101 # PROP Use_Debug_Libraries 0
102 # PROP Output_Dir ""
103 # PROP Intermediate_Dir ""
104 # PROP Cmd_Line "echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
105 # PROP Rebuild_Opt "-c && echo Starting SCons && "<PYTHON>" -c "<SCONS_SCRIPT_MAIN>" -C "<WORKPATH>" -f SConstruct "Test.exe""
106 # PROP Target_File "Test.exe"
107 # PROP Bsc_Name ""
108 # PROP Target_Dir ""
110 !ENDIF
112 # Begin Target
114 # Name "Test - Win32 Release"
116 !IF "$(CFG)" == "Test - Win32 Release"
118 !ENDIF
120 # Begin Group "Header Files"
122 # PROP Default_Filter "h;hpp;hxx;hm;inl"
123 # Begin Source File
125 SOURCE="sdk.h"
126 # End Source File
127 # End Group
128 # Begin Group "Local Headers"
130 # PROP Default_Filter "h;hpp;hxx;hm;inl"
131 # Begin Source File
133 SOURCE="test.h"
134 # End Source File
135 # End Group
136 # Begin Group "Other Files"
138 # PROP Default_Filter ""
139 # Begin Source File
141 SOURCE="readme.txt"
142 # End Source File
143 # End Group
144 # Begin Group "Resource Files"
146 # PROP Default_Filter "r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
147 # Begin Source File
149 SOURCE="test.rc"
150 # End Source File
151 # End Group
152 # Begin Group "Source Files"
154 # PROP Default_Filter "cpp;c;cxx;l;y;def;odl;idl;hpj;bat"
155 # Begin Source File
157 SOURCE="test.c"
158 # End Source File
159 # End Group
160 # Begin Source File
162 SOURCE="<SCONSCRIPT>"
163 # End Source File
164 # End Target
165 # End Project
168 expected_dswfile_6_0 = '''\
169 Microsoft Developer Studio Workspace File, Format Version 6.00
170 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
172 ###############################################################################
174 Project: "Test"="Test.dsp" - Package Owner=<4>
176 Package=<5>
180 Package=<4>
184 ###############################################################################
186 Global:
188 Package=<5>
192 Package=<3>
196 ###############################################################################
199 SConscript_contents_6_0 = """\
200 env=Environment(tools=['msvs'],
201 MSVS_VERSION='6.0',
202 HOST_ARCH='%(HOST_ARCH)s')
204 testsrc = ['test.c']
205 testincs = ['sdk.h']
206 testlocalincs = ['test.h']
207 testresources = ['test.rc']
208 testmisc = ['readme.txt']
210 env.MSVSProject(target = 'Test.dsp',
211 srcs = testsrc,
212 incs = testincs,
213 localincs = testlocalincs,
214 resources = testresources,
215 misc = testmisc,
216 buildtarget = 'Test.exe',
217 variant = 'Release')
221 expected_slnfile_7_0 = """\
222 Microsoft Visual Studio Solution File, Format Version 7.00
223 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "<PROJECT_GUID>"
224 EndProject
225 Global
226 <SCC_SLN_INFO>
227 \tGlobalSection(SolutionConfiguration) = preSolution
228 \t\tConfigName.0 = Release
229 \tEndGlobalSection
230 \tGlobalSection(ProjectDependencies) = postSolution
231 \tEndGlobalSection
232 \tGlobalSection(ProjectConfiguration) = postSolution
233 \t\t<PROJECT_GUID>.Release.ActiveCfg = Release|Win32
234 \t\t<PROJECT_GUID>.Release.Build.0 = Release|Win32
235 \tEndGlobalSection
236 \tGlobalSection(ExtensibilityGlobals) = postSolution
237 \tEndGlobalSection
238 \tGlobalSection(ExtensibilityAddIns) = postSolution
239 \tEndGlobalSection
240 EndGlobal
243 expected_vcprojfile_7_0 = """\
244 <?xml version="1.0" encoding="Windows-1252"?>
245 <VisualStudioProject
246 \tProjectType="Visual C++"
247 \tVersion="7.00"
248 \tName="Test"
249 \tProjectGUID="<PROJECT_GUID>"
250 <SCC_VCPROJ_INFO>
251 \tKeyword="MakeFileProj">
252 \t<Platforms>
253 \t\t<Platform
254 \t\t\tName="Win32"/>
255 \t</Platforms>
256 \t<Configurations>
257 \t\t<Configuration
258 \t\t\tName="Release|Win32"
259 \t\t\tOutputDirectory=""
260 \t\t\tIntermediateDirectory=""
261 \t\t\tConfigurationType="0"
262 \t\t\tUseOfMFC="0"
263 \t\t\tATLMinimizesCRunTimeLibraryUsage="FALSE">
264 \t\t\t<Tool
265 \t\t\t\tName="VCNMakeTool"
266 \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;"
267 \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;"
268 \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;"
269 \t\t\t\tOutput="Test.exe"/>
270 \t\t</Configuration>
271 \t</Configurations>
272 \t<Files>
273 \t\t<Filter
274 \t\t\tName="Header Files"
275 \t\t\tFilter="h;hpp;hxx;hm;inl">
276 \t\t\t<File
277 \t\t\t\tRelativePath="sdk.h">
278 \t\t\t</File>
279 \t\t</Filter>
280 \t\t<Filter
281 \t\t\tName="Local Headers"
282 \t\t\tFilter="h;hpp;hxx;hm;inl">
283 \t\t\t<File
284 \t\t\t\tRelativePath="test.h">
285 \t\t\t</File>
286 \t\t</Filter>
287 \t\t<Filter
288 \t\t\tName="Other Files"
289 \t\t\tFilter="">
290 \t\t\t<File
291 \t\t\t\tRelativePath="readme.txt">
292 \t\t\t</File>
293 \t\t</Filter>
294 \t\t<Filter
295 \t\t\tName="Resource Files"
296 \t\t\tFilter="r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
297 \t\t\t<File
298 \t\t\t\tRelativePath="test.rc">
299 \t\t\t</File>
300 \t\t</Filter>
301 \t\t<Filter
302 \t\t\tName="Source Files"
303 \t\t\tFilter="cpp;c;cxx;l;y;def;odl;idl;hpj;bat">
304 \t\t\t<File
305 \t\t\t\tRelativePath="test1.cpp">
306 \t\t\t</File>
307 \t\t\t<File
308 \t\t\t\tRelativePath="test2.cpp">
309 \t\t\t</File>
310 \t\t</Filter>
311 \t\t<File
312 \t\t\tRelativePath="<SCONSCRIPT>">
313 \t\t</File>
314 \t</Files>
315 \t<Globals>
316 \t</Globals>
317 </VisualStudioProject>
320 SConscript_contents_7_0 = """\
321 env=Environment(tools=['msvs'],
322 MSVS_VERSION='7.0',
323 HOST_ARCH='%(HOST_ARCH)s')
325 testsrc = ['test1.cpp', 'test2.cpp']
326 testincs = ['sdk.h']
327 testlocalincs = ['test.h']
328 testresources = ['test.rc']
329 testmisc = ['readme.txt']
331 env.MSVSProject(target = 'Test.vcproj',
332 MSVS_PROJECT_GUID = '%(PROJECT_GUID)s',
333 slnguid = '{SLNGUID}',
334 srcs = testsrc,
335 incs = testincs,
336 localincs = testlocalincs,
337 resources = testresources,
338 misc = testmisc,
339 buildtarget = 'Test.exe',
340 variant = 'Release')
344 expected_slnfile_7_1 = """\
345 Microsoft Visual Studio Solution File, Format Version 8.00
346 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Test", "Test.vcproj", "<PROJECT_GUID>"
347 \tProjectSection(ProjectDependencies) = postProject
348 \tEndProjectSection
349 EndProject
350 Global
351 <SCC_SLN_INFO>
352 \tGlobalSection(SolutionConfiguration) = preSolution
353 \t\tConfigName.0 = Release
354 \tEndGlobalSection
355 \tGlobalSection(ProjectDependencies) = postSolution
356 \tEndGlobalSection
357 \tGlobalSection(ProjectConfiguration) = postSolution
358 \t\t<PROJECT_GUID>.Release.ActiveCfg = Release|Win32
359 \t\t<PROJECT_GUID>.Release.Build.0 = Release|Win32
360 \tEndGlobalSection
361 \tGlobalSection(ExtensibilityGlobals) = postSolution
362 \tEndGlobalSection
363 \tGlobalSection(ExtensibilityAddIns) = postSolution
364 \tEndGlobalSection
365 EndGlobal
368 expected_vcprojfile_7_1 = """\
369 <?xml version="1.0" encoding="Windows-1252"?>
370 <VisualStudioProject
371 \tProjectType="Visual C++"
372 \tVersion="7.10"
373 \tName="Test"
374 \tProjectGUID="<PROJECT_GUID>"
375 <SCC_VCPROJ_INFO>
376 \tKeyword="MakeFileProj">
377 \t<Platforms>
378 \t\t<Platform
379 \t\t\tName="Win32"/>
380 \t</Platforms>
381 \t<Configurations>
382 \t\t<Configuration
383 \t\t\tName="Release|Win32"
384 \t\t\tOutputDirectory=""
385 \t\t\tIntermediateDirectory=""
386 \t\t\tConfigurationType="0"
387 \t\t\tUseOfMFC="0"
388 \t\t\tATLMinimizesCRunTimeLibraryUsage="FALSE">
389 \t\t\t<Tool
390 \t\t\t\tName="VCNMakeTool"
391 \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;"
392 \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;"
393 \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;"
394 \t\t\t\tOutput="Test.exe"/>
395 \t\t</Configuration>
396 \t</Configurations>
397 \t<References>
398 \t</References>
399 \t<Files>
400 \t\t<Filter
401 \t\t\tName="Header Files"
402 \t\t\tFilter="h;hpp;hxx;hm;inl">
403 \t\t\t<File
404 \t\t\t\tRelativePath="sdk.h">
405 \t\t\t</File>
406 \t\t</Filter>
407 \t\t<Filter
408 \t\t\tName="Local Headers"
409 \t\t\tFilter="h;hpp;hxx;hm;inl">
410 \t\t\t<File
411 \t\t\t\tRelativePath="test.h">
412 \t\t\t</File>
413 \t\t</Filter>
414 \t\t<Filter
415 \t\t\tName="Other Files"
416 \t\t\tFilter="">
417 \t\t\t<File
418 \t\t\t\tRelativePath="readme.txt">
419 \t\t\t</File>
420 \t\t</Filter>
421 \t\t<Filter
422 \t\t\tName="Resource Files"
423 \t\t\tFilter="r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
424 \t\t\t<File
425 \t\t\t\tRelativePath="test.rc">
426 \t\t\t</File>
427 \t\t</Filter>
428 \t\t<Filter
429 \t\t\tName="Source Files"
430 \t\t\tFilter="cpp;c;cxx;l;y;def;odl;idl;hpj;bat">
431 \t\t\t<File
432 \t\t\t\tRelativePath="test1.cpp">
433 \t\t\t</File>
434 \t\t\t<File
435 \t\t\t\tRelativePath="test2.cpp">
436 \t\t\t</File>
437 \t\t</Filter>
438 \t\t<File
439 \t\t\tRelativePath="<SCONSCRIPT>">
440 \t\t</File>
441 \t</Files>
442 \t<Globals>
443 \t</Globals>
444 </VisualStudioProject>
447 SConscript_contents_7_1 = """\
448 env=Environment(tools=['msvs'],
449 MSVS_VERSION='7.1',
450 HOST_ARCH='%(HOST_ARCH)s')
452 testsrc = ['test1.cpp', 'test2.cpp']
453 testincs = ['sdk.h']
454 testlocalincs = ['test.h']
455 testresources = ['test.rc']
456 testmisc = ['readme.txt']
458 env.MSVSProject(target = 'Test.vcproj',
459 MSVS_PROJECT_GUID = '%(PROJECT_GUID)s',
460 slnguid = '{SLNGUID}',
461 srcs = testsrc,
462 incs = testincs,
463 localincs = testlocalincs,
464 resources = testresources,
465 misc = testmisc,
466 buildtarget = 'Test.exe',
467 variant = 'Release')
471 expected_slnfile_fmt = """\
472 Microsoft Visual Studio Solution File, Format Version %(FORMAT_VERSION)s
473 # Visual Studio %(VS_NUMBER)s
474 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "%(PROJECT_NAME)s", "%(PROJECT_FILE)s", "<PROJECT_GUID>"
475 EndProject
476 Global
477 <SCC_SLN_INFO>
478 \tGlobalSection(SolutionConfigurationPlatforms) = preSolution
479 \t\tRelease|Win32 = Release|Win32
480 \tEndGlobalSection
481 \tGlobalSection(ProjectConfigurationPlatforms) = postSolution
482 \t\t<PROJECT_GUID>.Release|Win32.ActiveCfg = Release|Win32
483 \t\t<PROJECT_GUID>.Release|Win32.Build.0 = Release|Win32
484 \tEndGlobalSection
485 \tGlobalSection(SolutionProperties) = preSolution
486 \t\tHideSolutionNode = FALSE
487 \tEndGlobalSection
488 EndGlobal
491 expected_vcprojfile_fmt = """\
492 <?xml version="1.0" encoding="Windows-1252"?>
493 <VisualStudioProject
494 \tProjectType="Visual C++"
495 \tVersion="%(TOOLS_VERSION)s"
496 \tName="%(PROJECT_BASENAME)s"
497 \tProjectGUID="<PROJECT_GUID>"
498 \tRootNamespace="%(PROJECT_BASENAME)s"
499 <SCC_VCPROJ_INFO>
500 \tKeyword="MakeFileProj">
501 \t<Platforms>
502 \t\t<Platform
503 \t\t\tName="Win32"/>
504 \t</Platforms>
505 \t<ToolFiles>
506 \t</ToolFiles>
507 \t<Configurations>
508 \t\t<Configuration
509 \t\t\tName="Release|Win32"
510 \t\t\tConfigurationType="0"
511 \t\t\tUseOfMFC="0"
512 \t\t\tATLMinimizesCRunTimeLibraryUsage="false"
513 \t\t\t>
514 \t\t\t<Tool
515 \t\t\t\tName="VCNMakeTool"
516 \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;%(PROJECT_BASENAME)s.exe&quot;"
517 \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;%(PROJECT_BASENAME)s.exe&quot;"
518 \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;%(PROJECT_BASENAME)s.exe&quot;"
519 \t\t\t\tOutput="%(PROJECT_BASENAME)s.exe"
520 \t\t\t\tPreprocessorDefinitions="DEF1;DEF2;DEF3=1234"
521 \t\t\t\tIncludeSearchPath="%(INCLUDE_DIRS)s"
522 \t\t\t\tForcedIncludes=""
523 \t\t\t\tAssemblySearchPath=""
524 \t\t\t\tForcedUsingAssemblies=""
525 \t\t\t\tCompileAsManaged=""
526 \t\t\t/>
527 \t\t</Configuration>
528 \t</Configurations>
529 \t<References>
530 \t</References>
531 \t<Files>
532 \t\t<Filter
533 \t\t\tName="Header Files"
534 \t\t\tFilter="h;hpp;hxx;hm;inl">
535 \t\t\t<File
536 \t\t\t\tRelativePath="sdk_dir\\sdk.h">
537 \t\t\t</File>
538 \t\t</Filter>
539 \t\t<Filter
540 \t\t\tName="Local Headers"
541 \t\t\tFilter="h;hpp;hxx;hm;inl">
542 \t\t\t<File
543 \t\t\t\tRelativePath="test.h">
544 \t\t\t</File>
545 \t\t</Filter>
546 \t\t<Filter
547 \t\t\tName="Other Files"
548 \t\t\tFilter="">
549 \t\t\t<File
550 \t\t\t\tRelativePath="readme.txt">
551 \t\t\t</File>
552 \t\t</Filter>
553 \t\t<Filter
554 \t\t\tName="Resource Files"
555 \t\t\tFilter="r;rc;ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe">
556 \t\t\t<File
557 \t\t\t\tRelativePath="test.rc">
558 \t\t\t</File>
559 \t\t</Filter>
560 \t\t<Filter
561 \t\t\tName="Source Files"
562 \t\t\tFilter="cpp;c;cxx;l;y;def;odl;idl;hpj;bat">
563 \t\t\t<File
564 \t\t\t\tRelativePath="test1.cpp">
565 \t\t\t</File>
566 \t\t\t<File
567 \t\t\t\tRelativePath="test2.cpp">
568 \t\t\t</File>
569 \t\t</Filter>
570 \t\t<File
571 \t\t\tRelativePath="<SCONSCRIPT>">
572 \t\t</File>
573 \t</Files>
574 \t<Globals>
575 \t</Globals>
576 </VisualStudioProject>
579 expected_vcxprojfile_fmt = """\
580 <?xml version="1.0" encoding="utf-8"?>
581 <Project DefaultTargets="Build" ToolsVersion="%(TOOLS_VERSION)s" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
582 \t<ItemGroup Label="ProjectConfigurations">
583 \t\t<ProjectConfiguration Include="Release|Win32">
584 \t\t\t<Configuration>Release</Configuration>
585 \t\t\t<Platform>Win32</Platform>
586 \t\t</ProjectConfiguration>
587 \t</ItemGroup>
588 \t<PropertyGroup Label="Globals">
589 \t\t<ProjectGuid>%(PROJECT_GUID)s</ProjectGuid>
590 <SCC_VCPROJ_INFO>
591 \t\t<RootNamespace>%(PROJECT_BASENAME)s</RootNamespace>
592 \t\t<Keyword>MakeFileProj</Keyword>
593 \t\t<VCProjectUpgraderObjectName>NoUpgrade</VCProjectUpgraderObjectName>
594 \t</PropertyGroup>
595 \t<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.Default.props" />
596 \t<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
597 \t\t<ConfigurationType>Makefile</ConfigurationType>
598 \t\t<UseOfMfc>false</UseOfMfc>
599 \t\t<PlatformToolset>%(PLATFORM_TOOLSET)s</PlatformToolset>
600 \t</PropertyGroup>
601 \t<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.props" />
602 \t<ImportGroup Label="ExtensionSettings">
603 \t</ImportGroup>
604 \t<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
605 \t\t<Import Project="$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
606 \t</ImportGroup>
607 \t<PropertyGroup Label="UserMacros" />
608 \t<PropertyGroup>
609 \t<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
610 \t\t<NMakeBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">echo Starting SCons &amp;&amp; &quot;<PYTHON>&quot; -c &quot;<SCONS_SCRIPT_MAIN_XML>&quot; -C &quot;<WORKPATH>&quot; -f SConstruct &quot;%(PROJECT_BASENAME)s.exe&quot;</NMakeBuildCommandLine>
611 \t\t<NMakeReBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">echo Starting SCons &amp;&amp; &quot;<PYTHON>&quot; -c &quot;<SCONS_SCRIPT_MAIN_XML>&quot; -C &quot;<WORKPATH>&quot; -f SConstruct &quot;%(PROJECT_BASENAME)s.exe&quot;</NMakeReBuildCommandLine>
612 \t\t<NMakeCleanCommandLine Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">echo Starting SCons &amp;&amp; &quot;<PYTHON>&quot; -c &quot;<SCONS_SCRIPT_MAIN_XML>&quot; -C &quot;<WORKPATH>&quot; -f SConstruct -c &quot;%(PROJECT_BASENAME)s.exe&quot;</NMakeCleanCommandLine>
613 \t\t<NMakeOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PROJECT_BASENAME)s.exe</NMakeOutput>
614 \t\t<NMakePreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">DEF1;DEF2;DEF3=1234</NMakePreprocessorDefinitions>
615 \t\t<NMakeIncludeSearchPath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(INCLUDE_DIRS)s</NMakeIncludeSearchPath>
616 \t\t<NMakeForcedIncludes Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(NMakeForcedIncludes)</NMakeForcedIncludes>
617 \t\t<NMakeAssemblySearchPath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(NMakeAssemblySearchPath)</NMakeAssemblySearchPath>
618 \t\t<NMakeForcedUsingAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(NMakeForcedUsingAssemblies)</NMakeForcedUsingAssemblies>
619 \t\t<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"></AdditionalOptions>
620 \t</PropertyGroup>
621 \t<ItemGroup>
622 \t\t<ClInclude Include="sdk_dir\\sdk.h" />
623 \t</ItemGroup>
624 \t<ItemGroup>
625 \t\t<ClInclude Include="test.h" />
626 \t</ItemGroup>
627 \t<ItemGroup>
628 \t\t<None Include="readme.txt" />
629 \t</ItemGroup>
630 \t<ItemGroup>
631 \t\t<None Include="test.rc" />
632 \t</ItemGroup>
633 \t<ItemGroup>
634 \t\t<ClCompile Include="test1.cpp" />
635 \t\t<ClCompile Include="test2.cpp" />
636 \t</ItemGroup>
637 \t<ItemGroup>
638 \t\t<None Include="SConstruct" />
639 \t</ItemGroup>
640 \t<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.targets" />
641 \t<ImportGroup Label="ExtensionTargets">
642 \t</ImportGroup>
643 </Project>
646 SConscript_contents_fmt = """\
647 env=Environment(tools=['msvs'],
648 MSVS_VERSION='%(MSVS_VERSION)s',
649 CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
650 CPPPATH=['inc1', 'inc2'],
651 HOST_ARCH='%(HOST_ARCH)s')
653 testsrc = ['test1.cpp', 'test2.cpp']
654 testincs = [r'sdk_dir\\sdk.h']
655 testlocalincs = ['test.h']
656 testresources = ['test.rc']
657 testmisc = ['readme.txt']
659 env.MSVSProject(target = '%(PROJECT_FILE)s',
660 MSVS_PROJECT_GUID = '%(PROJECT_GUID)s',
661 slnguid = '{SLNGUID}',
662 srcs = testsrc,
663 incs = testincs,
664 localincs = testlocalincs,
665 resources = testresources,
666 misc = testmisc,
667 buildtarget = 'Test.exe',
668 variant = 'Release')
671 expected_projects_slnfile_fmt = """\
672 Microsoft Visual Studio Solution File, Format Version %(FORMAT_VERSION)s
673 # Visual Studio %(VS_NUMBER)s
674 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "%(PROJECT_NAME_1)s", "%(PROJECT_FILE_1)s", "<PROJECT_GUID_1>"
675 EndProject
676 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "%(PROJECT_NAME_2)s", "%(PROJECT_FILE_2)s", "<PROJECT_GUID_2>"
677 EndProject
678 Global
679 <SCC_SLN_INFO>
680 \tGlobalSection(SolutionConfigurationPlatforms) = preSolution
681 \t\tRelease|Win32 = Release|Win32
682 \tEndGlobalSection
683 \tGlobalSection(ProjectConfigurationPlatforms) = postSolution
684 \t\t<PROJECT_GUID_1>.Release|Win32.ActiveCfg = Release|Win32
685 \t\t<PROJECT_GUID_1>.Release|Win32.Build.0 = Release|Win32
686 \t\t<PROJECT_GUID_2>.Release|Win32.ActiveCfg = Release|Win32
687 \t\t<PROJECT_GUID_2>.Release|Win32.Build.0 = Release|Win32
688 \tEndGlobalSection
689 \tGlobalSection(SolutionProperties) = preSolution
690 \t\tHideSolutionNode = FALSE
691 \tEndGlobalSection
692 EndGlobal
695 expected_projects_slnfile_fmt_slnnodes = """\
696 Microsoft Visual Studio Solution File, Format Version %(FORMAT_VERSION)s
697 # Visual Studio %(VS_NUMBER)s
698 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "%(PROJECT_NAME_1)s", "%(PROJECT_FILE_1)s", "<PROJECT_GUID_1>"
699 EndProject
700 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "%(SOLUTION_FILE_1)s", "%(SOLUTION_FILE_1)s", "<SOLUTION_GUID_1>"
701 EndProject
702 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "%(PROJECT_NAME_2)s", "%(PROJECT_FILE_2)s", "<PROJECT_GUID_2>"
703 EndProject
704 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "%(SOLUTION_FILE_2)s", "%(SOLUTION_FILE_2)s", "<SOLUTION_GUID_2>"
705 EndProject
706 Global
707 <SCC_SLN_INFO>
708 \tGlobalSection(SolutionConfigurationPlatforms) = preSolution
709 \t\tRelease|Win32 = Release|Win32
710 \tEndGlobalSection
711 \tGlobalSection(ProjectConfigurationPlatforms) = postSolution
712 \t\t<PROJECT_GUID_1>.Release|Win32.ActiveCfg = Release|Win32
713 \t\t<PROJECT_GUID_1>.Release|Win32.Build.0 = Release|Win32
714 \t\t<SOLUTION_GUID_1>.Release|Win32.ActiveCfg = Release|Win32
715 \t\t<SOLUTION_GUID_1>.Release|Win32.Build.0 = Release|Win32
716 \t\t<PROJECT_GUID_2>.Release|Win32.ActiveCfg = Release|Win32
717 \t\t<PROJECT_GUID_2>.Release|Win32.Build.0 = Release|Win32
718 \t\t<SOLUTION_GUID_2>.Release|Win32.ActiveCfg = Release|Win32
719 \t\t<SOLUTION_GUID_2>.Release|Win32.Build.0 = Release|Win32
720 \tEndGlobalSection
721 \tGlobalSection(SolutionProperties) = preSolution
722 \t\tHideSolutionNode = FALSE
723 \tEndGlobalSection
724 EndGlobal
727 SConscript_projects_contents_fmt = """\
728 env=Environment(
729 tools=['msvs'],
730 MSVS_VERSION='%(MSVS_VERSION)s',
731 CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
732 CPPPATH=['inc1', 'inc2'],
733 HOST_ARCH='%(HOST_ARCH)s',
736 testsrc = ['test1.cpp', 'test2.cpp']
737 testincs = [r'sdk_dir\\sdk.h']
738 testlocalincs = ['test.h']
739 testresources = ['test.rc']
740 testmisc = ['readme.txt']
742 p1 = env.MSVSProject(
743 target = '%(PROJECT_FILE_1)s',
744 MSVS_PROJECT_GUID = '%(PROJECT_GUID_1)s',
745 slnguid = '{SLNGUID}',
746 srcs = testsrc,
747 incs = testincs,
748 localincs = testlocalincs,
749 resources = testresources,
750 misc = testmisc,
751 buildtarget = 'Test_1.exe',
752 variant = 'Release',
753 auto_build_solution = %(AUTOBUILD_SOLUTION)s,
756 p2 = env.MSVSProject(
757 target = '%(PROJECT_FILE_2)s',
758 MSVS_PROJECT_GUID = '%(PROJECT_GUID_2)s',
759 slnguid = '{SLNGUID}',
760 srcs = testsrc,
761 incs = testincs,
762 localincs = testlocalincs,
763 resources = testresources,
764 misc = testmisc,
765 buildtarget = 'Test_2.exe',
766 variant = 'Release',
767 auto_build_solution = %(AUTOBUILD_SOLUTION)s,
770 env.MSVSSolution(
771 target = '%(SOLUTION_FILE)s',
772 projects = [p1, p2],
773 variant = 'Release',
774 auto_filter_projects = %(AUTOFILTER_PROJECTS)s,
778 SConscript_projects_defaultguids_contents_fmt = """\
779 env=Environment(
780 tools=['msvs'],
781 MSVS_VERSION='%(MSVS_VERSION)s',
782 CPPDEFINES=['DEF1', 'DEF2',('DEF3','1234')],
783 CPPPATH=['inc1', 'inc2'],
784 HOST_ARCH='%(HOST_ARCH)s',
787 testsrc = ['test1.cpp', 'test2.cpp']
788 testincs = [r'sdk_dir\\sdk.h']
789 testlocalincs = ['test.h']
790 testresources = ['test.rc']
791 testmisc = ['readme.txt']
793 p1 = env.MSVSProject(
794 target = '%(PROJECT_FILE_1)s',
795 slnguid = '{SLNGUID}',
796 srcs = testsrc,
797 incs = testincs,
798 localincs = testlocalincs,
799 resources = testresources,
800 misc = testmisc,
801 buildtarget = 'Test_1.exe',
802 variant = 'Release',
803 auto_build_solution = %(AUTOBUILD_SOLUTION)s,
806 p2 = env.MSVSProject(
807 target = '%(PROJECT_FILE_2)s',
808 slnguid = '{SLNGUID}',
809 srcs = testsrc,
810 incs = testincs,
811 localincs = testlocalincs,
812 resources = testresources,
813 misc = testmisc,
814 buildtarget = 'Test_2.exe',
815 variant = 'Release',
816 auto_build_solution = %(AUTOBUILD_SOLUTION)s,
819 env.MSVSSolution(
820 target = '%(SOLUTION_FILE)s',
821 projects = [p1, p2],
822 variant = 'Release',
823 auto_filter_projects = %(AUTOFILTER_PROJECTS)s,
828 def get_tested_proj_file_vc_versions():
830 Returns all MSVC versions that we want to test project file creation for.
832 return ['8.0', '9.0', '10.0', '11.0', '12.0', '14.0', '14.1', '14.2', '14.3']
835 class TestSConsMSVS(TestSCons):
836 """Subclass for testing MSVS-specific portions of SCons."""
838 def msvs_versions(self):
839 if not hasattr(self, '_msvs_versions'):
840 # Determine the SCons version and the versions of the MSVS
841 # environments installed on the test machine.
843 # We do this by executing SCons with an SConstruct file
844 # (piped on stdin) that spits out Python assignments that
845 # we can just exec(). We construct the SCons.__"version"__
846 # string in the input here so that the SCons build itself
847 # doesn't fill it in when packaging SCons.
848 input = (
849 """\
850 import SCons
851 import SCons.Tool.MSCommon
852 print("self.scons_version =%%s"%%repr(SCons.__%s__))
853 print("self._msvs_versions =%%s"%%str(SCons.Tool.MSCommon.query_versions(env=None)))
855 % 'version'
858 self.run(arguments='-n -q -Q -f -', stdin=input)
859 exec(self.stdout())
861 return self._msvs_versions
863 def vcproj_sys_path(self, fname) -> None:
864 """ """
865 orig = 'sys.path = [ join(sys'
867 enginepath = repr(os.path.join(self._cwd, '..', 'engine'))
868 replace = f'sys.path = [ {enginepath}, join(sys'
870 contents = self.read(fname, mode='r')
871 contents = contents.replace(orig, replace)
872 self.write(fname, contents)
874 def msvs_substitute(
875 self,
876 input,
877 msvs_ver,
878 subdir=None,
879 sconscript=None,
880 python=None,
881 project_guid=None,
882 vcproj_sccinfo: str = '',
883 sln_sccinfo: str = '',
885 if not hasattr(self, '_msvs_versions'):
886 self.msvs_versions()
888 if subdir:
889 workpath = self.workpath(subdir)
890 else:
891 workpath = self.workpath()
893 if sconscript is None:
894 sconscript = self.workpath('SConstruct')
896 if python is None:
897 python = sys.executable
899 if project_guid is None:
900 project_guid = PROJECT_GUID
902 if 'SCONS_LIB_DIR' in os.environ:
903 exec_script_main = f"from os.path import join; import sys; sys.path = [ r'{os.environ['SCONS_LIB_DIR']}' ] + sys.path; import SCons.Script; SCons.Script.main()"
904 else:
905 exec_script_main = f"from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-{self.scons_version}'), join(sys.prefix, 'scons-{self.scons_version}'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons') ] + sys.path; import SCons.Script; SCons.Script.main()"
906 exec_script_main_xml = exec_script_main.replace("'", "&apos;")
908 result = input.replace(r'<WORKPATH>', workpath)
909 result = result.replace(r'<PYTHON>', python)
910 result = result.replace(r'<SCONSCRIPT>', sconscript)
911 result = result.replace(r'<SCONS_SCRIPT_MAIN>', exec_script_main)
912 result = result.replace(r'<SCONS_SCRIPT_MAIN_XML>', exec_script_main_xml)
913 result = result.replace(r'<PROJECT_GUID>', project_guid)
914 result = result.replace('<SCC_VCPROJ_INFO>\n', vcproj_sccinfo)
915 result = result.replace('<SCC_SLN_INFO>\n', sln_sccinfo)
916 return result
918 def get_msvs_executable(self, version, env=None):
919 """Returns a full path to the executable (MSDEV or devenv)
920 for the specified version of Visual Studio.
922 from SCons.Tool.MSCommon import get_vs_by_version
924 msvs = get_vs_by_version(version, env)
925 if not msvs:
926 return None
927 return msvs.get_executable()
929 def run(self, *args, **kw):
931 Suppress MSVS deprecation warnings.
933 save_sconsflags = os.environ.get('SCONSFLAGS')
934 if save_sconsflags:
935 sconsflags = [save_sconsflags]
936 else:
937 sconsflags = []
938 sconsflags = sconsflags + ['--warn=no-deprecated']
939 os.environ['SCONSFLAGS'] = ' '.join(sconsflags)
940 try:
941 result = TestSCons.run(self, *args, **kw)
942 finally:
943 os.environ['SCONSFLAGS'] = save_sconsflags or ''
944 return result
946 def get_vs_host_arch(self):
947 """Returns an MSVS, SDK, and/or MSVS acceptable platform arch."""
949 # Dict to 'canonicalize' the arch (synchronize with MSCommon\vc.py)
950 _ARCH_TO_CANONICAL = {
951 "amd64": "amd64",
952 "emt64": "amd64",
953 "i386": "x86",
954 "i486": "x86",
955 "i586": "x86",
956 "i686": "x86",
957 "ia64": "ia64", # deprecated
958 "itanium": "ia64", # deprecated
959 "x86": "x86",
960 "x86_64": "amd64",
961 "arm": "arm",
962 "arm64": "arm64",
963 "aarch64": "arm64",
966 host_platform = None
968 if winreg:
969 try:
970 winkey = winreg.OpenKeyEx(
971 winreg.HKEY_LOCAL_MACHINE,
972 r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
974 host_platform, _ = winreg.QueryValueEx(winkey, 'PROCESSOR_ARCHITECTURE')
975 except OSError:
976 pass
978 if not host_platform:
979 host_platform = platform.machine()
981 try:
982 host = _ARCH_TO_CANONICAL[host_platform.lower()]
983 except KeyError as e:
984 # Default to x86 for all other platforms
985 host = 'x86'
987 return host
989 def validate_msvs_file(self, file) -> None:
990 try:
991 x = ElementTree.parse(file)
992 except:
993 print("--------------------------------------------------------------")
994 print("--------------------------------------------------------------")
995 print(traceback.format_exc())
996 print("Failed to validate xml in MSVS file: ")
997 print(file)
998 print("--------------------------------------------------------------")
999 print("--------------------------------------------------------------")
1000 self.fail_test()
1002 def parse_vc_version(self, vc_version):
1004 Parses the string vc_version to determine the major and minor version
1005 included.
1007 components = vc_version.split('.')
1008 major = int(components[0])
1009 minor = 0 if len(components) < 2 else int(components[1])
1010 return major, minor
1012 def _get_solution_file_format_version(self, vc_version) -> str:
1014 Returns the Visual Studio format version expected in the .sln file.
1016 major, _ = self.parse_vc_version(vc_version)
1017 if major == 8:
1018 return '9.00'
1019 elif major == 9:
1020 return '10.00'
1021 elif major == 10:
1022 return '11.00'
1023 elif major > 10:
1024 return '12.00'
1025 else:
1026 raise SCons.Errors.UserError(f'Received unexpected VC version {vc_version}')
1028 def _get_solution_file_vs_number(self, vc_version) -> str:
1030 Returns the Visual Studio number expected in the .sln file.
1032 major, minor = self.parse_vc_version(vc_version)
1033 if major == 8:
1034 return '2005'
1035 elif major == 9:
1036 return '2008'
1037 if major == 10:
1038 return '2010'
1039 elif major == 11:
1040 return '11'
1041 elif major == 12:
1042 return '14'
1043 elif major == 14 and (minor == 0 or minor == 1):
1044 # Visual Studio 2015 and 2017 both use 15 in this entry.
1045 return '15'
1046 elif major == 14 and minor == 2:
1047 return '16'
1048 elif major == 14 and minor == 3:
1049 return '17'
1050 else:
1051 raise SCons.Errors.UserError(f'Received unexpected VC version {vc_version}')
1053 def _get_vcxproj_file_tools_version(self, vc_version) -> str:
1055 Returns the version entry expected in the project file.
1056 For .vcxproj files, this goes is ToolsVersion.
1057 For .vcproj files, this goes in Version.
1059 major, minor = self.parse_vc_version(vc_version)
1060 if major == 8:
1061 # Version="8.00"
1062 return '8.00'
1063 elif major == 9:
1064 # Version="9.00"
1065 return '9.00'
1066 elif major < 14:
1067 # ToolsVersion='4.0'
1068 return '4.0'
1069 elif major == 14 and minor == 0:
1070 # ToolsVersion='14.0'
1071 return '14.0'
1072 elif major == 14 and minor == 1:
1073 # ToolsVersion='15.0'
1074 return '15.0'
1075 elif vc_version == '14.2':
1076 # ToolsVersion='16'
1077 return '16.0'
1078 elif vc_version == '14.3':
1079 # ToolsVersion='17'
1080 return '17.0'
1081 else:
1082 raise SCons.Errors.UserError(f'Received unexpected VC version {vc_version}')
1084 def _get_vcxproj_file_platform_toolset(self, vc_version) -> str:
1086 Returns the version entry expected in the project file.
1087 For .vcxproj files, this goes is PlatformToolset.
1088 For .vcproj files, not applicable.
1090 major, minor = self.parse_vc_version(vc_version)
1091 return f"v{major}{minor}"
1093 def _get_vcxproj_file_cpp_path(self, dirs):
1094 """Returns the include paths expected in the .vcxproj file"""
1095 return ';'.join([self.workpath(dir) for dir in dirs])
1097 def get_expected_sln_file_contents(self, vc_version, project_file):
1099 Returns the expected .sln file contents.
1100 Currently this function only supports the newer VC versions that use
1101 the .vcxproj file format.
1103 return expected_slnfile_fmt % {
1104 'FORMAT_VERSION': self._get_solution_file_format_version(vc_version),
1105 'VS_NUMBER': self._get_solution_file_vs_number(vc_version),
1106 'PROJECT_NAME': project_file.split('.')[0],
1107 'PROJECT_FILE': project_file,
1110 def get_expected_proj_file_contents(self, vc_version, dirs, project_file):
1111 """Returns the expected .vcxproj file contents"""
1112 if project_file.endswith('.vcxproj'):
1113 fmt = expected_vcxprojfile_fmt
1114 else:
1115 fmt = expected_vcprojfile_fmt
1116 project_filename = os.path.split(project_file)[-1]
1117 project_basename = os.path.splitext(project_filename)[0]
1118 return fmt % {
1119 'PROJECT_BASENAME': project_basename,
1120 'PROJECT_GUID': PROJECT_GUID,
1121 'TOOLS_VERSION': self._get_vcxproj_file_tools_version(vc_version),
1122 'INCLUDE_DIRS': self._get_vcxproj_file_cpp_path(dirs),
1123 'PLATFORM_TOOLSET': self._get_vcxproj_file_platform_toolset(vc_version),
1126 def get_expected_sconscript_file_contents(self, vc_version, project_file):
1127 return SConscript_contents_fmt % {
1128 'HOST_ARCH': self.get_vs_host_arch(),
1129 'MSVS_VERSION': vc_version,
1130 'PROJECT_GUID': PROJECT_GUID,
1131 'PROJECT_FILE': project_file,
1134 def msvs_substitute_projects(
1135 self,
1136 input,
1138 subdir=None,
1139 sconscript=None,
1140 python=None,
1141 project_guid_1=None,
1142 project_guid_2=None,
1143 solution_guid_1=None,
1144 solution_guid_2=None,
1145 vcproj_sccinfo: str = '',
1146 sln_sccinfo: str = '',
1148 if not hasattr(self, '_msvs_versions'):
1149 self.msvs_versions()
1151 if subdir:
1152 workpath = self.workpath(subdir)
1153 else:
1154 workpath = self.workpath()
1156 if sconscript is None:
1157 sconscript = self.workpath('SConstruct')
1159 if python is None:
1160 python = sys.executable
1162 if project_guid_1 is None:
1163 project_guid_1 = PROJECT_GUID_1
1165 if project_guid_2 is None:
1166 project_guid_2 = PROJECT_GUID_2
1168 if solution_guid_1 is None:
1169 solution_guid_1 = SOLUTION_GUID_1
1171 if solution_guid_2 is None:
1172 solution_guid_2 = SOLUTION_GUID_2
1174 if 'SCONS_LIB_DIR' in os.environ:
1175 exec_script_main = f"from os.path import join; import sys; sys.path = [ r'{os.environ['SCONS_LIB_DIR']}' ] + sys.path; import SCons.Script; SCons.Script.main()"
1176 else:
1177 exec_script_main = f"from os.path import join; import sys; sys.path = [ join(sys.prefix, 'Lib', 'site-packages', 'scons-{self.scons_version}'), join(sys.prefix, 'scons-{self.scons_version}'), join(sys.prefix, 'Lib', 'site-packages', 'scons'), join(sys.prefix, 'scons') ] + sys.path; import SCons.Script; SCons.Script.main()"
1178 exec_script_main_xml = exec_script_main.replace("'", "&apos;")
1180 result = input.replace(r'<WORKPATH>', workpath)
1181 result = result.replace(r'<PYTHON>', python)
1182 result = result.replace(r'<SCONSCRIPT>', sconscript)
1183 result = result.replace(r'<SCONS_SCRIPT_MAIN>', exec_script_main)
1184 result = result.replace(r'<SCONS_SCRIPT_MAIN_XML>', exec_script_main_xml)
1185 result = result.replace(r'<PROJECT_GUID_1>', project_guid_1)
1186 result = result.replace(r'<PROJECT_GUID_2>', project_guid_2)
1187 result = result.replace(r'<SOLUTION_GUID_1>', solution_guid_1)
1188 result = result.replace(r'<SOLUTION_GUID_2>', solution_guid_2)
1189 result = result.replace('<SCC_VCPROJ_INFO>\n', vcproj_sccinfo)
1190 result = result.replace('<SCC_SLN_INFO>\n', sln_sccinfo)
1191 return result
1193 def get_expected_projects_proj_file_contents(
1194 self, vc_version, dirs, project_file, project_guid
1196 """Returns the expected .vcxproj file contents"""
1197 if project_file.endswith('.vcxproj'):
1198 fmt = expected_vcxprojfile_fmt
1199 else:
1200 fmt = expected_vcprojfile_fmt
1201 project_filename = os.path.split(project_file)[-1]
1202 project_basename = os.path.splitext(project_filename)[0]
1203 return fmt % {
1204 'PROJECT_BASENAME': project_basename,
1205 'PROJECT_GUID': project_guid,
1206 'TOOLS_VERSION': self._get_vcxproj_file_tools_version(vc_version),
1207 'INCLUDE_DIRS': self._get_vcxproj_file_cpp_path(dirs),
1208 'PLATFORM_TOOLSET': self._get_vcxproj_file_platform_toolset(vc_version),
1211 def get_expected_projects_sln_file_contents(
1212 self,
1213 vc_version,
1214 project_file_1,
1215 project_file_2,
1216 have_solution_project_nodes=False,
1217 autofilter_solution_project_nodes=None,
1219 if not have_solution_project_nodes or autofilter_solution_project_nodes:
1220 rval = expected_projects_slnfile_fmt % {
1221 'FORMAT_VERSION': self._get_solution_file_format_version(vc_version),
1222 'VS_NUMBER': self._get_solution_file_vs_number(vc_version),
1223 'PROJECT_NAME_1': project_file_1.split('.')[0],
1224 'PROJECT_FILE_1': project_file_1,
1225 'PROJECT_NAME_2': project_file_2.split('.')[0],
1226 'PROJECT_FILE_2': project_file_2,
1228 else:
1229 rval = expected_projects_slnfile_fmt_slnnodes % {
1230 'FORMAT_VERSION': self._get_solution_file_format_version(vc_version),
1231 'VS_NUMBER': self._get_solution_file_vs_number(vc_version),
1232 'PROJECT_NAME_1': project_file_1.split('.')[0],
1233 'PROJECT_FILE_1': project_file_1,
1234 'PROJECT_NAME_2': project_file_2.split('.')[0],
1235 'PROJECT_FILE_2': project_file_2,
1236 'SOLUTION_FILE_1': project_file_1.split('.')[0] + ".sln",
1237 'SOLUTION_FILE_2': project_file_2.split('.')[0] + ".sln",
1239 return rval
1241 def get_expected_projects_sconscript_file_contents(
1242 self,
1243 vc_version,
1244 project_file_1,
1245 project_file_2,
1246 solution_file,
1247 autobuild_solution=0,
1248 autofilter_projects=None,
1249 default_guids=False,
1251 values = {
1252 'HOST_ARCH': self.get_vs_host_arch(),
1253 'MSVS_VERSION': vc_version,
1254 'PROJECT_FILE_1': project_file_1,
1255 'PROJECT_FILE_2': project_file_2,
1256 'SOLUTION_FILE': solution_file,
1257 "AUTOBUILD_SOLUTION": autobuild_solution,
1258 "AUTOFILTER_PROJECTS": autofilter_projects,
1261 if default_guids:
1262 format = SConscript_projects_defaultguids_contents_fmt
1263 else:
1264 format = SConscript_projects_contents_fmt
1266 values.update(
1268 'PROJECT_GUID_1': PROJECT_GUID_1,
1269 'PROJECT_GUID_2': PROJECT_GUID_2,
1272 return format % values
1275 # Local Variables:
1276 # tab-width:4
1277 # indent-tabs-mode:nil
1278 # End:
1279 # vim: set expandtab tabstop=4 shiftwidth=4: