vcxprojtool.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # @brief VCXProject file generator
00004 # @date $Date: 2008-02-29 04:52:14 $
00005 # @author Norkai Ando <n-ando@aist.go.jp>
00006 #
00007 # Copyright (C) 2008
00008 #     Noriaki Ando
00009 #     Task-intelligence Research Group,
00010 #     Intelligent Systems Research Institute,
00011 #     National Institute of
00012 #         Advanced Industrial Science and Technology (AIST), Japan
00013 #     All rights reserved.
00014 #
00015 # $Id: vcxprojtool.py 1668 2010-01-16 17:13:48Z n-ando $
00016 #
00017 
00018 #------------------------------------------------------------
00019 # Generic vcxproj template
00020 #------------------------------------------------------------
00021 vcxproj_template = """<?xml version="1.0" encoding="utf-8"?>
00022 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
00023   <ItemGroup Label="ProjectConfigurations">
00024     <ProjectConfiguration Include="Debug|Win32">
00025       <Configuration>Debug</Configuration>
00026       <Platform>Win32</Platform>
00027     </ProjectConfiguration>
00028     <ProjectConfiguration Include="Release|Win32">
00029       <Configuration>Release</Configuration>
00030       <Platform>Win32</Platform>
00031     </ProjectConfiguration>
00032   </ItemGroup>
00033   <PropertyGroup Label="Globals">
00034     <ProjectName>[RootNamespace]</ProjectName>
00035     <ProjectGuid>{[ProjectGUID]}</ProjectGuid>
00036     <RootNamespace>[RootNamespace]</RootNamespace>
00037     <Keyword>Win32Proj</Keyword>
00038   </PropertyGroup>
00039   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
00040 [for conf in Configurations]
00041   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='[conf.Name]'" Label="Configuration">
00042     <ConfigurationType>%s</ConfigurationType>
00043     <CharacterSet>NotSet</CharacterSet>
00044   </PropertyGroup>
00045 [endfor]
00046   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
00047   <ImportGroup Label="ExtensionSettings">
00048   </ImportGroup>
00049 [for conf in Configurations]
00050   <ImportGroup Condition="'$(Configuration)|$(Platform)'=='[conf.Name]'" Label="PropertySheets">
00051     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
00052 [for inher in conf.VC10_InheritedPropertySheets]
00053 [if-any inher]
00054     <Import Project="[inher]" />
00055 [endif]
00056 [endfor]
00057   </ImportGroup>
00058 [endfor]
00059   <PropertyGroup Label="UserMacros" />
00060   <PropertyGroup>
00061     <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
00062 [for conf in Configurations]
00063     <OutDir Condition="'$(Configuration)|$(Platform)'=='[conf.Name]'">[conf.VC10_OutputDirectory]</OutDir>
00064     <IntDir Condition="'$(Configuration)|$(Platform)'=='[conf.Name]'">[conf.VC10_IntermediateDirectory]</IntDir>
00065     <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='[conf.Name]'">[conf.VC10_LinkIncrementalCondition]</LinkIncremental>
00066 [endfor]
00067   </PropertyGroup>
00068 
00069 [for conf in Configurations]
00070   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='[conf.Name]'">
00071     <!-- PreBuildEvent -->
00072     <PreBuildEvent>
00073 %s
00074     </PreBuildEvent>
00075     <!-- ClCompile -->
00076     <ClCompile>
00077 %s
00078     </ClCompile>
00079     <!-- Lib -->
00080     <Lib>
00081 %s
00082     </Lib>
00083     <!-- PreLinkEvent -->
00084     <PreLinkEvent>
00085 %s
00086     </PreLinkEvent>
00087     <!-- Link -->
00088     <Link>
00089 %s
00090     </Link>
00091     <!-- PostBuildEvent -->
00092     <PostBuildEvent>
00093 %s
00094     </PostBuildEvent>
00095   </ItemDefinitionGroup>
00096 [endfor]
00097   <ItemGroup>
00098 [if-any Source]
00099     <Filter Include="[Source.Name]">
00100       <UniqueIdentifier>{[Source.GUID]}</UniqueIdentifier>
00101       <Extensions>[Source.Filter]</Extensions>
00102     </Filter>
00103 [endif]
00104 [if-any Header]
00105     <Filter Include="[Header.Name]">
00106       <UniqueIdentifier>{[Header.GUID]}</UniqueIdentifier>
00107       <Extensions>[Header.Filter]</Extensions>
00108     </Filter>
00109 [endif]
00110   </ItemGroup>
00111   <ItemGroup>
00112 [if-any Source.Files][for file in Source.Files]
00113     <ClCompile Include="[file.Path]">
00114       <Filter>[Source.Name]</Filter>
00115     </ClCompile>
00116 [endfor][endif]
00117   </ItemGroup>
00118   <ItemGroup>
00119 [if-any Header.Files][for file in Header.Files]
00120     <ClInclude Include="[file.Path]">
00121       <Filter>[Header.Name]</Filter>
00122     </ClInclude>
00123 [endfor][endif]
00124   </ItemGroup>
00125   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
00126   <ImportGroup Label="ExtensionTargets">
00127   </ImportGroup>
00128 </Project>
00129 
00130 """
00131 
00132 #------------------------------------------------------------
00133 # ConfigurationType
00134 #------------------------------------------------------------
00135 conf_type = {"EXE": "Application", "DLL": "DynamicLibrary", 
00136              "NMAKE": "Makefile", 
00137              "LIB": "StaticLibrary",
00138              "RTCEXE": "Application", "RTCDLL": "DynamicLibrary"}
00139 
00140 
00141 #------------------------------------------------------------
00142 # Tool set for configuration
00143 #------------------------------------------------------------
00144 PreBuildEventtools = {"EXE":
00145              ["PreBuildEvent",
00146               "VCCustomBuildTool",
00147               "VCXMLDataGeneratorTool",
00148               "VCWebServiceProxyGeneratorTool",
00149               "VCMIDLTool",
00150               "VCManagedResourceCompilerTool",
00151               "VCResourceCompilerTool",
00152               "VCManifestTool"],
00153          "DLL":
00154              ["PreBuildEvent"],
00155          "LIB":
00156              ["PreBuildEvent"]
00157          }
00158 PreBuildEventtools["RTCEXE"] = PreBuildEventtools["EXE"]
00159 PreBuildEventtools["RTCDLL"] = PreBuildEventtools["DLL"]
00160 Cltools = {"EXE":
00161              ["VCCustomBuildTool",
00162               "VCXMLDataGeneratorTool",
00163               "VCWebServiceProxyGeneratorTool",
00164               "VCMIDLTool",
00165               "VC10_VCCLCompilerTool",
00166               "VCManagedResourceCompilerTool",
00167               "VCResourceCompilerTool",
00168               "VCManifestTool"],
00169          "DLL":
00170              ["VCCustomBuildTool",
00171               "VCXMLDataGeneratorTool",
00172               "VCWebServiceProxyGeneratorTool",
00173               "VCMIDLTool",
00174               "VC10_VCCLCompilerTool",
00175               "VCManagedResourceCompilerTool",
00176               "VCResourceCompilerTool",
00177               "VCManifestTool"],
00178          "LIB":
00179              ["VCCustomBuildTool",
00180               "VCXMLDataGeneratorTool",
00181               "VCWebServiceProxyGeneratorTool",
00182               "VCMIDLTool",
00183               "VC10_VCCLCompilerTool",
00184               "VCManagedResourceCompilerTool",
00185               "VCResourceCompilerTool"]
00186          }
00187 Cltools["RTCEXE"] = Cltools["EXE"]
00188 Cltools["RTCDLL"] = Cltools["DLL"]
00189 Libtools = {"EXE":
00190              ["VCLibrarianTool"],
00191          "DLL":
00192              ["VCLibrarianTool"],
00193          "LIB":
00194              ["VCLibrarianTool"]
00195          }
00196 Libtools["RTCEXE"] = Libtools["EXE"]
00197 Libtools["RTCDLL"] = Libtools["DLL"]
00198 PreLinkEventtools = {"EXE":
00199              ["VC10_VCPreLinkEventTool"],
00200          "DLL":
00201              ["VC10_VCPreLinkEventTool"],
00202          "LIB":
00203              [""]
00204          }
00205 PreLinkEventtools["RTCEXE"] = PreLinkEventtools["EXE"]
00206 PreLinkEventtools["RTCDLL"] = PreLinkEventtools["DLL"]
00207 Linktools = {"EXE":
00208              ["VC10_VCPreLinkEventTool",
00209               "VC10_VCLinkerTool",
00210               "VCALinkTool",
00211               "VCManifestTool",
00212               "VCXDCMakeTool",
00213               "VCBscMakeTool",
00214               "VCFxCopTool",
00215               "VCAppVerifierTool",
00216               "VCWebDeploymentTool"],
00217          "DLL":
00218              ["VC10_VCLinkerTool",
00219               "VCALinkTool",
00220               "VCManifestTool",
00221               "VCXDCMakeTool",
00222               "VCBscMakeTool",
00223               "VCFxCopTool",
00224               "VCAppVerifierTool",
00225               "VCWebDeploymentTool"],
00226          "LIB":
00227              [""]
00228          }
00229 Linktools["RTCEXE"] = Linktools["EXE"]
00230 Linktools["RTCDLL"] = Linktools["DLL"]
00231 PostBuildEventtools = {"EXE":
00232              ["VC10_VCPreLinkEventTool",
00233               "VC10_VCLinkerTool",
00234               "VCALinkTool",
00235               "VCManifestTool",
00236               "VCXDCMakeTool",
00237               "VCBscMakeTool",
00238               "VCFxCopTool",
00239               "VCAppVerifierTool",
00240               "VCWebDeploymentTool",
00241               "VC10_VCPostBuildEventTool"],
00242          "DLL":
00243              ["VC10_VCPostBuildEventTool"],
00244          "LIB":
00245              ["VC10_VCPostBuildEventTool"]
00246          }
00247 PostBuildEventtools["RTCEXE"] = PostBuildEventtools["EXE"]
00248 PostBuildEventtools["RTCDLL"] = PostBuildEventtools["DLL"]
00249 
00250 
00251 #------------------------------------------------------------
00252 # Tool element
00253 #------------------------------------------------------------
00254 tool_elem = """[if-any conf.%s][for tool in conf.%s]
00255 [if-any tool.Key]
00256       <[tool.Key]>[tool.Value]</[tool.Key]>
00257 [endif]
00258 [endfor][endif]"""
00259 
00260 
00261 exeproj_yaml = """
00262 ProjectType: Visual C++
00263 Version: "__VCVERSION__"
00264 Name: # Your Project Name
00265 ProjectGUID: __GUID__
00266 RootNamespace: 
00267 Keyword: Win32Proj
00268 Platforms:
00269   Platform:
00270     Name: Win32
00271 Configurations:
00272   - Name: Debug
00273     VC10_OutputDirectory: $(ProjectDir)$(Configuration)
00274     VC10_IntermediateDirectory: $(Configuration)
00275     VC10_InheritedPropertySheets: # Set vsprops file if you need
00276 """
00277 
00278 
00279 #------------------------------------------------------------
00280 # Yaml template
00281 #------------------------------------------------------------
00282 exe_yaml = """ProjectType: "Visual C++"
00283 Version: "__VCVERSION__"
00284 Name: __PROJECT_NAME__
00285 ProjectGUID: __GUID__
00286 RootNamespace: __PROJECT_NAME__
00287 Keyword: "Win32Proj"
00288 Configurations:
00289 #------------------------------------------------------------
00290 # Debug Configuration
00291 #------------------------------------------------------------
00292   - Name: "Debug|Win32"
00293     VC10_OutputDirectory: $(ProjectDir)$(Configuration)"
00294     VC10_IntermediateDirectory: "$(Configuratio)"
00295     ConfigurationType: "1"
00296 #    VC10_InheritedPropertySheets:
00297     CharacterSet: "0"
00298     VC10_LinkIncrementalCondition: "true"
00299 #    VCPreBuildEventTool:
00300 #    VCCustomBuildTool:
00301 #    VCXMLDataGeneratorTool:
00302 #    VCWebServiceProxyGeneratorTool:
00303 #    VCMIDLTool:
00304     VC10_VCCLCompilerTool:
00305       - Key: Optimization
00306         Value: Disabled 
00307       - Key: PreprocessorDefinitions
00308         Value: "WIN32;_DEBUG;_CONSOLE;__WIN32__;__x86__;_WIN32_WINNT=0x0400;__NT__;__OSVERSION__=4;%(PreprocessorDefinitions)"
00309       - Key: MinimalRebuild
00310         Value: "true"
00311       - Key: BasicRuntimeChecks
00312         Value: "EnableFastChecks"
00313       - Key: RuntimeLibrary
00314         Value: "MultiThreadedDebugDLL"
00315       - Key: PrecompiledHeader
00316         Value: "NotUsing"
00317       - Key: WarningLevel
00318         Value: "Level3"
00319       - Key: Detect64BitPortabilityProblems
00320         Value: "false"
00321       - Key: DebugInformationFormat
00322         Value: "EditAndContinue"
00323 #    VCManagedResourceCompilerTool:
00324 #    VCResourceCompilerTool:
00325 #    VC10_VCPreLinkEventTool:
00326     VC10_VCLinkerTool:
00327       - Key: AdditionalDependencies
00328         Value: ""
00329       - Key: OutputFile
00330         Value: "$(OutDir)\\\\__PROJECT_NAME__.exe"
00331       - Key: LinkIncremental
00332         Value: "2"
00333       - Key: IgnoreDefaultLibraryNames
00334         Value: ""
00335       - Key: GenerateDebugInformation
00336         Value: "true"
00337       - Key: SubSystem
00338         Value: "Console"
00339       - Key: TargetMachine
00340         Value: "MachineX86"
00341 #    VCALinkTool:
00342 #    VCManifestTool:
00343 #    VCXDCMakeTool:
00344 #    VCBscMakeTool:
00345 #    VCFxCopTool:
00346 #    VCAppVerifierTool:
00347 #    VCWebDeploymentTool:
00348     VC_10VCPostBuildEventTool:
00349     VCPreLinkEvent: 'lib -out:"$(TargetDir)coil_static.lib" "$(TargetDir)*.obj"
00350 set PATH=%PATH%%3b$(coil_path)
00351 cd "$(TargetDir)"
00352 start /wait cmd /c makedeffile.py coil_static.lib coil$(coil_dllver)d $(coil_version) coil$(coil_dllver)d.def
00353 move coil$(coil_dllver)d.def ..\'
00354     VC10_VCPostBuildEventTool: 'copy "$(OutDir)\$(TargetName).lib" "$(SolutionDir)bin\\coil$(coil_dllver)d.lib"
00355 copy "$(OutDir)\coil$(coil_dllver)d.dll" "$(SolutionDir)bin\\"'
00356     VCPreLinkEvent: 'lib -out:"$(TargetDir)coil_static.lib" "$(TargetDir)*.obj"
00357 set PATH=%PATH%%3b$(coil_path)
00358 cd "$(OutDir)"
00359 start /wait cmd /c makedeffile.py coil_static.lib coil$(coil_dllver) $(coil_version) coil$(coil_dllver).def
00360 move coil$(coil_dllver).def ..\\'
00361     VC10_VCPostBuildEventTool: 'copy "$(OutDir)\$(TargetName).lib" "$(SolutionDir)bin\\coil$(coil_dllver).lib"
00362 copy "$(OutDir)\coil$(coil_dllver).dll" "$(SolutionDir)bin\\"'
00363 #------------------------------------------------------------
00364 # Release Configuration
00365 #------------------------------------------------------------
00366   - Name: "Release|Win32"
00367     VC10_OutputDirectory: $(ProjectDir)$(Configuration)"
00368     VC10_IntermediateDirectory: "$(Configuratio)"
00369     ConfigurationType: "1"
00370 #    VC10_InheritedPropertySheets: ""
00371     CharacterSet: "0"
00372     VC10_LinkIncrementalCondition: "false"
00373     WholeProgramOptimization: "0"
00374 #    VCPreBuildEventTool:
00375 #    VCCustomBuildTool:
00376 #    VCXMLDataGeneratorTool:
00377 #    VCWebServiceProxyGeneratorTool:
00378 #    VCMIDLTool:
00379     VC10_VCCLCompilerTool:
00380       - Key: PreprocessorDefinitions
00381         Value: "WIN32;NDEBUG;_CONSOLE;__WIN32__;__x86__;_WIN32_WINNT=0x0400;__NT__;__OSVERSION__=4;%(PreprocessorDefinitions)"
00382       - Key: RuntimeLibrary
00383         Value: "MultiThreadedDLL"
00384       - Key: PrecompiledHeader
00385         Value: "NotUsing"
00386       - Key: WarningLevel
00387         Value: "Level3"
00388       - Key: Detect64BitPortabilityProblems
00389         Value: "false"
00390       - Key: DebugInformationFormat
00391         Value: "ProgramDatabase"
00392 #    VCManagedResourceCompilerTool"
00393 #    VCResourceCompilerTool"
00394 #    VC10_VCPreLinkEventTool"
00395     VC10_VCLinkerTool:
00396       - Key: AdditionalDependencies
00397         Value: ""
00398       - Key: OutputFile
00399         Value: "$(OutDir)\\\\__PROJECT_NAME__.exe"
00400       - Key: LinkIncremental
00401         Value: "1"
00402       - Key: GenerateDebugInformation
00403         Value: "false"
00404       - Key: SubSystem
00405         Value: "Console"
00406       - Key: OptimizeReferences
00407         Value: "true"
00408       - Key: EnableCOMDATFolding
00409         Value: "true"
00410       - Key: LinkTimeCodeGeneration
00411         Value: ""
00412       - Key: TargetMachine
00413         Value: "MachineX86"
00414 #    VCALinkTool:
00415 #    VCManifestTool:
00416 #    VCXDCMakeTool:
00417 #    VCBscMakeTool:
00418 #    VCFxCopTool:
00419 #    VCAppVerifierTool:
00420 #    VCWebDeploymentTool:
00421 #    VC10_VCPostBuildEventTool:
00422 """
00423 
00424 dll_yaml = """ProjectType: "Visual C++"
00425 Version: "__VCVERSION__"
00426 Name: __PROJECT_NAME__
00427 ProjectGUID: __GUID__
00428 RootNamespace: __PROJECT_NAME__
00429 Keyword: "Win32Proj"
00430 Configurations:
00431   - Name: "Debug|Win32"
00432     VC10_OutputDirectory: "$(ProjectDir)$(Configuration)"
00433     VC10_IntermediateDirectory: "$(Configuration)"
00434     ConfigurationType: "2"
00435 #    VC10_InheritedPropertySheets: ""
00436     CharacterSet: "0"
00437     VC10_LinkIncrementalCondition: "true"
00438 #    VCPreBuildEventTool:
00439 #    VCCustomBuildTool:
00440 #    VCXMLDataGeneratorTool:
00441 #    VCWebServiceProxyGeneratorTool:
00442 #    VCMIDLTool:
00443     VC10_VCCLCompilerTool:
00444       - Key: Optimization
00445         Value: "Disabled"
00446       - Key: PreprocessorDefinitions
00447         Value: "WIN32;_DEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE"
00448       - Key: MinimalRebuild
00449         Value: "true"
00450       - Key: BasicRuntimeChecks
00451         Value: "EnableFastChecks"
00452       - Key: RuntimeLibrary
00453         Value: "MultiThreadedDebugDLL"
00454       - Key: PrecompiledHeader
00455         Value: "NotUsing"
00456       - Key: WarningLevel
00457         Value: "Level3"
00458       - Key: Detect64BitPortabilityProblems
00459         Value: "false"
00460       - Key: DebugInformationFormat
00461         Value: "EditAndContinue"
00462 #    VCManagedResourceCompilerTool:
00463 #    VCResourceCompilerTool:
00464     VC10_VCPreLinkEventTool:
00465       - Key: Command
00466         Value: |
00467           lib -out:"$(TargetDir)RTC_static.lib" "$(TargetDir)*.obj" "$(SolutionDir)\\\\rtm\\\\idl\\\\$(ConfigurationName)\\\\*.obj"
00468           set PATH=%PATH%;$(rtm_path)
00469           cd $(OutDir)
00470           start /wait cmd /c makedeffile.py RTC_static.lib RTC042d 0.4.1 RTC042d.def
00471           move RTC042d.def ..\\\\
00472     VC10_VCLinkerTool:
00473       - Key: AdditionalDependencies
00474         Value: ""
00475       - Key: OutputFile
00476         Value: "$(OutDir)\\\\__PROJECT_NAME__.dll"
00477       - Key: Version
00478         Value: __VERSION__
00479       - Key: LinkIncremental
00480         Value: "2"
00481       - Key: ModuleDefinitionFile
00482         Value: "$(TargetName).def"
00483       - Key: GenerateDebugInformation
00484         Value: "true"
00485       - Key: SubSystem
00486         Value: "Windows"
00487       - Key: TargetMachine
00488         Value: "MachineX86"
00489 #    VCALinkTool:
00490 #    VCManifestTool:
00491 #    VCXDCMakeTool:
00492 #    VCBscMakeTool:
00493 #    VCFxCopTool:
00494 #    VCAppVerifierTool:
00495 #    VCWebDeploymentTool:
00496     VC10_VCPostBuildEventTool:
00497       - Key: Command
00498         Value: |
00499           copy "$(OutDir)\\\\$(TargetName).lib" "$(SolutionDir)bin\\\\"
00500           copy "$(OutDir)\\\\$(TargetName).dll" "$(SolutionDir)bin\\\\"
00501   - Name: "Release|Win32"
00502     VC10_OutputDirectory: "$(ProjectDir)$(Configuration)"
00503     VC10_IntermediateDirectory: "$(Configuration)"
00504     ConfigurationType: "2"
00505     VC10_InheritedPropertySheets: ""
00506     CharacterSet: "0"
00507     VC10_LinkIncrementalCondition: "false"
00508     WholeProgramOptimization: "0"
00509 #    VCPreBuildEventTool:
00510 #    VCCustomBuildTool:
00511 #    VCXMLDataGeneratorTool:
00512 #    VCWebServiceProxyGeneratorTool:
00513 #    VCMIDLTool:
00514     VC10_VCCLCompilerTool:
00515       - Key: PreprocessorDefinitions
00516         Value: "WIN32;NDEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
00517       - Key:         RuntimeLibrary
00518         Value: "MultiThreadedDLL"
00519       - Key:         UsePrecompiledHeader
00520         Value: "NotUsing"
00521       - Key:         WarningLevel
00522         Value: "Level3"
00523       - Key:         Detect64BitPortabilityProblems
00524         Value: "false"
00525       - Key:         DebugInformationFormat
00526         Value: "ProgramDatabase"
00527 #    VCManagedResourceCompilerTool:
00528 #    VCResourceCompilerTool:
00529     VC10_VCPreLinkEventTool:
00530       - Key: Command
00531         Value: |
00532           lib -out:"$(TargetDir)RTC_static.lib" "$(TargetDir)*.obj" "$(SolutionDir)\\\\rtm\\\\idl\\\\$(ConfigurationName)\\\\*.obj"
00533           set PATH=%PATH%;$(rtm_path)
00534           cd "$(OutDir)"
00535           start /wait cmd /c makedeffile.py RTC_static.lib RTC042 0.4.1 RTC042.def
00536           move RTC042.def ..\\\\
00537     VC10_VCLinkerTool:
00538       - Key: AdditionalDependencies
00539         Value: ""
00540       - Key: OutputFile
00541         Value: "$(OutDir)\\\\__PROJECT_NAME__.dll"
00542       - Key: LinkIncremental
00543         Value: "1"
00544       - Key: ModuleDefinitionFile
00545         Value: "$(TargetName).def"
00546       - Key: GenerateDebugInformation
00547         Value: "false"
00548       - Key: SubSystem
00549         Value: "Windows"
00550       - Key: OptimizeReferences
00551         Value: "true"
00552       - Key: EnableCOMDATFolding
00553         Value: "true"
00554       - Key: TargetMachine
00555         Value: "MachineX86"
00556 #    VCALinkTool:
00557 #    VCManifestTool:
00558 #    VCXDCMakeTool:
00559 #    VCBscMakeTool:
00560 #    VCFxCopTool:
00561 #    VCAppVerifierTool:
00562 #    VCWebDeploymentTool:
00563     VC10_VCPostBuildEventTool:
00564       - Key: Command
00565         Value: |
00566           copy "$(OutDir)\\\\$(TargetName).lib" "$(SolutionDir)bin\\\\"
00567           copy "$(OutDir)\\\\$(TargetName).dll" "$(SolutionDir)bin\\\\"
00568 """
00569 #------------------------------------------------------------
00570 lib_yaml = """ProjectType: "Visual C++"
00571 Version: "__VCVERSION__"
00572 Name: __PROJECT_NAME__
00573 ProjectGUID: __GUID__
00574 RootNamespace: __PROJECT_NAME__
00575 Keyword: "Win32Proj"
00576 Configurations:
00577   - Name: "Debug|Win32"
00578     VC10_OutputDirectory: "$(ProjectDir)$(Configuration)"
00579     VC10_IntermediateDirectory: "$(Configuration)"
00580     ConfigurationType: "4"
00581 #    VC10_InheritedPropertySheets: "..\\\\..\\\\OpenRTM-aist.vsprops"
00582     CharacterSet: "0"
00583     VC10_LinkIncrementalCondition: "true"
00584     DeleteExtensionsOnClean: ""
00585     PreBuildEvent:
00586       - Key: Command
00587         Value: |
00588           set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
00589           for %%x in (*.idl) do makewrapper.py %%x
00590           for %%x in (*.idl) do omniidl -bcxx -Wba -nf %%x
00591 #    VCCustomBuildTool:
00592 #    VCXMLDataGeneratorTool:
00593 #    VCWebServiceProxyGeneratorTool:
00594 #    VCMIDLTool:
00595     VC10_VCCLCompilerTool:
00596       - Key: Optimization
00597         Value: "Disabled"
00598       - Key: PreprocessorDefinitions
00599         Value: "WIN32;_DEBUG;_LIB;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
00600       - Key: MinimalRebuild
00601         Value: "true"
00602       - Key: BasicRuntimeChecks
00603         Value: "EnableFastChecks"
00604       - Key: RuntimeLibrary
00605         Value: "MultiThreadedDebugDLL"
00606       - Key: PrecompiledHeader
00607         Value: "NotUsing"
00608       - Key: WarningLevel
00609         Value: "Level3"
00610       - Key: Detect64BitPortabilityProblems
00611         Value: "false"
00612       - Key: DebugInformationFormat
00613         Value: "EditAndContinue"
00614 #    VCManagedResourceCompilerTool:
00615 #    VCResourceCompilerTool:
00616 #    VC10_VCPreLinkEventTool:
00617     VCLibrarianTool:
00618       - Key: OutputFile
00619         Value: "$(OutDir)\\\\__PROJECT_NAME__.lib"
00620 #    VCALinkTool:
00621 #    VCXDCMakeTool:
00622 #    VCBscMakeTool:
00623 #    VCFxCopTool:
00624     VC10_VCPostBuildEventTool:
00625       - Key: Description
00626         Value: "make .def file"
00627       - Key: Command
00628         Value: |
00629           copy "$(OutDir)\\\\libRTCSkeld.lib" "$(SolutionDir)\\\\bin"
00630   - Name: "Release|Win32"
00631     VC10_OutputDirectory: "$(ProjectDir)$(Configuration)"
00632     VC10_IntermediateDirectory: "$(Configuration)"
00633     ConfigurationType: "4"
00634 #    VC10_InheritedPropertySheets: "..\\\\..\\\\OpenRTM-aist.vsprops"
00635     CharacterSet: "0"
00636     VC10_LinkIncrementalCondition: "false"
00637     WholeProgramOptimization: "0"
00638     PreBuildEvent:
00639       - Key: Command
00640         Value: |
00641           set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
00642           for %%x in (*.idl) do makewrapper.py %%x
00643           for %%x in (*.idl) do omniidl -bcxx -Wba -nf %%x
00644 #    VCCustomBuildTool:
00645 #    VCXMLDataGeneratorTool:
00646 #    VCWebServiceProxyGeneratorTool:
00647 #    VCMIDLTool:
00648     VC10_VCCLCompilerTool:
00649       - Key: PreprocessorDefinitions
00650         Value: "WIN32;NDEBUG;_LIB;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
00651       - Key: RuntimeLibrary
00652         Value: "MultiThreadedDLL"
00653       - Key: PrecompiledHeader
00654         Value: "NotUsing"
00655       - Key: WarningLevel
00656         Value: "Level3"
00657       - Key: Detect64BitPortabilityProblems
00658         Value: "false"
00659       - Key: DebugInformationFormat
00660         Value: "ProgramDatabase"
00661 #    VCManagedResourceCompilerTool:
00662 #    VCResourceCompilerTool:
00663 #    VC10_VCPreLinkEventTool:
00664     VCLibrarianTool:
00665       - Key: OutputFile
00666         Value: "$(OutDir)\\\\__PROJECT_NAME__.lib"
00667 #    VCALinkTool:
00668 #    VCXDCMakeTool:
00669 #    VCBscMakeTool:
00670 #    VCFxCopTool:
00671     VC10_VCPostBuildEventTool:
00672       - Key: Command
00673         Value: |
00674           copy "$(OutDir)\\\\libRTCSkel.lib" "$(SolutionDir)\\\\bin"
00675 """
00676 
00677 
00678 rtcexe_yaml="""ProjectType: "Visual C++"
00679 Version: "__VCVERSION__"
00680 Name: __PROJECT_NAME__
00681 ProjectGUID: __GUID__
00682 RootNamespace: __PROJECT_NAME__
00683 Keyword: "Win32Proj"
00684 Configurations:
00685 #------------------------------------------------------------
00686 # Debug Configuration
00687 #------------------------------------------------------------
00688   - Name: "Debug|Win32"
00689     VC10_OutputDirectory: "$(ProjectDir)__PROJECT_NAME__\\\\$(Configuration)"
00690     VC10_IntermediateDirectory: "__PROJECT_NAME__\\\\$(Configuration)"
00691     ConfigurationType: "1"
00692     VC10_InheritedPropertySheets: 
00693       - "$(SolutionDir)user_config.props"
00694       - "$(SolutionDir)rtm_config.props"
00695     CharacterSet: "0"
00696     VC10_LinkIncrementalCondition: "true"
00697     PreBuildEvent:
00698       - Key: Command
00699         Value: |
00700           set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
00701           for %%x in (*.idl) do rtm-skelwrapper.py --include-dir="" --skel-suffix=Skel --stub-suffix=Stub --idl-file=%%x
00702           for %%x in (*.idl) do $(rtm_idlc) $(rtm_idlflags) %%x
00703     VC10_VCCLCompilerTool:
00704       - Key: Optimization
00705         Value: Disabled
00706       - Key: PreprocessorDefinitions
00707         Value: "USE_stub_in_nt_dll;WIN32;_DEBUG;_CONSOLE;__WIN32__;__x86__;_WIN32_WINNT=0x0400;__NT__;__OSVERSION__=4;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
00708       - Key: MinimalRebuild
00709         Value: "true"
00710       - Key: BasicRuntimeChecks
00711         Value: "EnableFastChecks"
00712       - Key: RuntimeLibrary
00713         Value: "MultiThreadedDebugDLL"
00714       - Key: PrecompiledHeader
00715         Value: "NotUsing"
00716       - Key: WarningLevel
00717         Value: "Level3"
00718       - Key: Detect64BitPortabilityProblems
00719         Value: "false"
00720       - Key: DebugInformationFormat
00721         Value: "EditAndContinue"
00722     VC10_VCLinkerTool:
00723       - Key: AdditionalDependencies
00724         Value: "$(rtm_libd);%(AdditionalDependencies)"
00725       - Key: OutputFile
00726         Value: "$(OutDir)\\\\__PROJECT_NAME__.exe"
00727       - Key: LinkIncremental
00728         Value: "2"
00729       - Key: GenerateDebugInformation
00730         Value: "true"
00731       - Key: SubSystem
00732         Value: "Console"
00733       - Key: TargetMachine
00734         Value: "MachineX86"
00735 #------------------------------------------------------------
00736 # Release Configuration
00737 #------------------------------------------------------------
00738   - Name: "Release|Win32"
00739     VC10_OutputDirectory: "$(ProjectDir)__PROJECT_NAME__\\\\$(Configuration)"
00740     VC10_IntermediateDirectory: "__PROJECT_NAME__\\\\$(Configuration)"
00741     ConfigurationType: "1"
00742     VC10_InheritedPropertySheets: 
00743       - "$(SolutionDir)user_config.props"
00744       - "$(SolutionDir)rtm_config.props"
00745     CharacterSet: "0"
00746     VC10_LinkIncrementalCondition: "false"
00747     WholeProgramOptimization: "0"
00748     PreBuildEvent:
00749       - Key: Command
00750         Value: |
00751           set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
00752           for %%x in (*.idl) do rtm-skelwrapper.py --include-dir="" --skel-suffix=Skel --stub-suffix=Stub --idl-file=%%x
00753           for %%x in (*.idl) do $(rtm_idlc) $(rtm_idlflags) %%x
00754     VC10_VCPostBuildEventTool:
00755       - Key: Command
00756         Value: |
00757           if NOT EXIST "$(SolutionDir)\\\\components" mkdir "$(SolutionDir)\\\\components"
00758           copy "$(OutDir)\\\\__PROJECT_NAME__.exe" "$(SolutionDir)\\\\components"
00759     VC10_VCCLCompilerTool:
00760       - Key: PreprocessorDefinitions
00761         Value: "USE_stub_in_nt_dll;WIN32;NDEBUG;_CONSOLE;__WIN32__;__x86__;_WIN32_WINNT=0x0400;__NT__;__OSVERSION__=4;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
00762       - Key: RuntimeLibrary
00763         Value: "MultiThreadedDLL"
00764       - Key: PrecompiledHeader
00765         Value: "NotUsing"
00766       - Key: WarningLevel
00767         Value: "Level3"
00768       - Key: Detect64BitPortabilityProblems
00769         Value: "false"
00770       - Key: DebugInformationFormat
00771         Value: "ProgramDatabase"
00772     VC10_VCLinkerTool:
00773 
00774       - Key: AdditionalDependencies
00775         Value: "$(rtm_lib);%(AdditionalDependencies)"
00776       - Key: OutputFile
00777         Value: "$(OutDir)\\\\__PROJECT_NAME__.exe"
00778       - Key: LinkIncremental
00779         Value: "1"
00780       - Key: GenerateDebugInformation
00781         Value: "false"
00782       - Key: SubSystem
00783         Value: "Console"
00784       - Key: OptimizeReferences
00785         Value: "true"
00786       - Key: EnableCOMDATFolding
00787         Value: "true"
00788       - Key: LinkTimeCodeGeneration
00789         Value: ""
00790       - Key: TargetMachine
00791         Value: "MachineX86"
00792 """
00793 
00794 rtcdll_yaml="""ProjectType: "Visual C++"
00795 Version: "__VCVERSION__"
00796 Name: __PROJECT_NAME__
00797 ProjectGUID: __GUID__
00798 RootNamespace: __PROJECT_NAME__
00799 Keyword: "Win32Proj"
00800 Configurations:
00801 #------------------------------------------------------------
00802 # Debug Configuration
00803 #------------------------------------------------------------
00804   - Name: "Debug|Win32"
00805     VC10_OutputDirectory: "$(ProjectDir)__PROJECT_NAME__\\\\$(Configuration)"
00806     VC10_IntermediateDirectory: "__PROJECT_NAME__\\\\$(Configuration)"
00807     ConfigurationType: "2"
00808     VC10_InheritedPropertySheets: 
00809       - "$(SolutionDir)user_config.props"
00810       - "$(SolutionDir)rtm_config.props"
00811     CharacterSet: "0"
00812     VC10_LinkIncrementalCondition: "true"
00813     PreBuildEvent:
00814       - Key: Command
00815         Value: |
00816           set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
00817           for %%x in (*.idl) do rtm-skelwrapper.py --include-dir="" --skel-suffix=Skel --stub-suffix=Stub --idl-file=%%x
00818           for %%x in (*.idl) do $(rtm_idlc) $(rtm_idlflags) %%x
00819     VC10_VCCLCompilerTool:
00820       - Key: Optimization
00821         Value: "Disabled"
00822       - Key: PreprocessorDefinitions
00823         Value: "USE_stub_in_nt_dll;WIN32;_DEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
00824       - Key: MinimalRebuild
00825         Value: "true"
00826       - Key: BasicRuntimeChecks
00827         Value: "EnableFastChecks"
00828       - Key: RuntimeLibrary
00829         Value: "MultiThreadedDebugDLL"
00830       - Key: PrecompiledHeader
00831         Value: "NotUsing"
00832       - Key: WarningLevel
00833         Value: "Level3"
00834       - Key: Detect64BitPortabilityProblems
00835         Value: "false"
00836       - Key: DebugInformationFormat
00837         Value: "EditAndContinue"
00838     VC10_VCLinkerTool:
00839       - Key: AdditionalDependencies
00840         Value: "$(rtm_libd);%(AdditionalDependencies)"
00841 #      - Key: OutputFile
00842 #        Value: "$(OutDir)\\\\__PROJECT_NAME__.dll"
00843 #      - Key: Version
00844 #        Value: __VERSION__
00845       - Key: LinkIncremental
00846         Value: "2"
00847 #      - Key: ModuleDefinitionFile
00848 #        Value: "$(TargetName).def"
00849       - Key: GenerateDebugInformation
00850         Value: "true"
00851       - Key: SubSystem
00852         Value: "Windows"
00853       - Key: TargetMachine
00854         Value: "MachineX86"
00855 #------------------------------------------------------------
00856 # Release Configuration
00857 #------------------------------------------------------------
00858   - Name: "Release|Win32"
00859     VC10_OutputDirectory: "$(ProjectDir)__PROJECT_NAME__\\\\$(Configuration)"
00860     VC10_IntermediateDirectory: "__PROJECT_NAME__\\\\$(Configuration)"
00861     ConfigurationType: "2"
00862     VC10_InheritedPropertySheets: 
00863       - "$(SolutionDir)user_config.props"
00864       - "$(SolutionDir)rtm_config.props"
00865     CharacterSet: "0"
00866     VC10_LinkIncrementalCondition: "false"
00867     WholeProgramOptimization: "0"
00868     PreBuildEvent:
00869       - Key: Command
00870         Value: |
00871           set PATH=$(rtm_path);%PYTHON_ROOT%\\\\;%PATH%
00872           for %%x in (*.idl) do rtm-skelwrapper.py --include-dir="" --skel-suffix=Skel --stub-suffix=Stub --idl-file=%%x
00873           for %%x in (*.idl) do $(rtm_idlc) $(rtm_idlflags) %%x
00874     VC10_VCPostBuildEventTool:
00875       - Key: Command
00876         Value: |
00877           if NOT EXIST "$(SolutionDir)\\\\components" mkdir "$(SolutionDir)\\\\components"
00878           copy "$(OutDir)\\\\__PROJECT_NAME__.dll" "$(SolutionDir)\\\\components"
00879     VC10_VCCLCompilerTool:
00880       - Key: PreprocessorDefinitions
00881         Value: "USE_stub_in_nt_dll;WIN32;NDEBUG;_WINDOWS;_USRDLL;__WIN32__;__NT__;__OSVERSION__=4;__x86__;_WIN32_WINNT=0x0400;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)"
00882       - Key:         RuntimeLibrary
00883         Value: "MultiThreadedDLL"
00884       - Key:         PrecompiledHeader
00885         Value: "NotUsing"
00886       - Key:         WarningLevel
00887         Value: "Level3"
00888       - Key:         Detect64BitPortabilityProblems
00889         Value: "false"
00890       - Key:         DebugInformationFormat
00891         Value: "ProgramDatabase"
00892     VC10_VCLinkerTool:
00893       - Key: AdditionalDependencies
00894         Value: "$(rtm_lib);%(AdditionalDependencies)"
00895 #      - Key: OutputFile
00896 #        Value: "$(OutDir)\\\\__PROJECT_NAME__.dll"
00897       - Key: LinkIncremental
00898         Value: "1"
00899 #      - Key: ModuleDefinitionFile
00900 #        Value: "$(TargetName).def"
00901       - Key: GenerateDebugInformation
00902         Value: "false"
00903       - Key: SubSystem
00904         Value: "Windows"
00905       - Key: OptimizeReferences
00906         Value: "true"
00907       - Key: EnableCOMDATFolding
00908         Value: "true"
00909       - Key: TargetMachine
00910         Value: "MachineX86"
00911 """
00912 
00913 
00914 
00915 def usage():
00916     print """Usage:
00917   vcprojtool.py cmd options
00918 commands:
00919   vcproj: Generate vcproj
00920   yaml  : Generate example yaml file
00921   flist : Generate file list as yaml
00922 examples:
00923   vcprojtool.py vcproj --type [exe|dll|nmake|lib]
00924                      --output out_fname
00925                      --yaml *.yaml
00926                      --source *.cpp
00927                      --header *.h
00928                      --resource *.txt
00929   vcprojtool.py yaml --type [exe|dll|nmake|lib] --output
00930   vcprojtool.py flist --out --source|--header|--resource *
00931 """
00932 
00933 import sys
00934 
00935 #------------------------------------------------------------
00936 # Exceptions
00937 #------------------------------------------------------------
00938 class VCProjException:
00939     pass
00940 
00941 class InvalidOption(VCProjException):
00942     def __init__(self, msg):
00943         self.msg = "Error: InvalidOption:\n    "
00944         self.msg += msg
00945 
00946 class InvalidCommand(VCProjException):
00947     def __init__(self, msg):
00948         self.msg = "Error: InvalidCommand:\n    "
00949         self.msg += msg
00950 
00951 #------------------------------------------------------------
00952 # VCProject generator class
00953 #------------------------------------------------------------
00954 class VCProject:
00955     def __init__(self, type, yaml_text):
00956         import yaml
00957         self.type = type
00958         self.dict = yaml.load(yaml_text)
00959         self.escape_cmdline(self.dict)
00960 
00961     def generate(self):
00962         import yat
00963         self.template = yat.Template(self.get_template(self.type))
00964         return self.template.generate(self.dict).replace("\r\n", "\n").replace("\n", "\r\n")
00965 
00966     def PreBuildEventtool_element(self, type):
00967         text = ""
00968         for tool in PreBuildEventtools[type]:
00969             t = tool_elem % (tool, tool)
00970             text += t
00971         return text
00972 
00973     def CLtool_element(self, type):
00974         text = ""
00975         for tool in Cltools[type]:
00976             t = tool_elem % (tool, tool)
00977             text += t
00978         return text
00979 
00980     def Libtool_element(self, type):
00981         text = ""
00982         for tool in Libtools[type]:
00983             t = tool_elem % (tool, tool)
00984             text += t
00985         return text
00986 
00987     def PreLinkEventtool_element(self, type):
00988         text = ""
00989         for tool in PreLinkEventtools[type]:
00990             t = tool_elem % (tool, tool)
00991             text += t
00992         return text
00993 
00994     def Linktool_element(self, type):
00995         text = ""
00996         for tool in Linktools[type]:
00997             t = tool_elem % (tool, tool)
00998             text += t
00999         return text
01000 
01001     def PostBuildEventtool_element(self, type):
01002         text = ""
01003         for tool in PostBuildEventtools[type]:
01004             t = tool_elem % (tool, tool)
01005             text += t
01006         return text
01007 
01008 
01009     def get_template(self, type):
01010         #return vcxproj_template % (conf_type[type], conf_type[type], self.tool_element(type))
01011         return vcxproj_template % (conf_type[type], self.PreBuildEventtool_element(type), self.CLtool_element(type), self.Libtool_element(type), self.PreLinkEventtool_element(type), self.Linktool_element(type), self.PostBuildEventtool_element(type))
01012 
01013     def escape_cmdline(self, dict):
01014         if not dict.has_key("Configurations"): return
01015     
01016         def escape_cmd(text):
01017             text = text.replace("\"", "&quot;")
01018             text = text.replace("\r\n", "\n")
01019             text = text.replace("\n", "&#x0D;&#x0A;")
01020             return text
01021         from types import DictType, ListType
01022         for conf in dict["Configurations"]:
01023             for tool in conf.keys(): # Tool
01024                 if isinstance(conf[tool], ListType):
01025                     for keyval in conf[tool]:
01026                         if isinstance(keyval, DictType) \
01027                                 and keyval.has_key("Key") \
01028                                 and keyval.has_key("Value") \
01029                                 and keyval["Key"] == "Command":
01030                             keyval["Value"] = escape_cmd(keyval["Value"])
01031 
01032 #------------------------------------------------------------
01033 # YAML configuration file generator
01034 #------------------------------------------------------------
01035 class YamlConfig:
01036     def __init__(self, type, vcversion, projectname, version, flist):
01037         self.type = type
01038         self.vcversion = vcversion
01039         self.projectname = projectname
01040         self.version = version
01041         self.flist = flist
01042 
01043         self.yaml_template = {"EXE": exe_yaml, "DLL": dll_yaml, "LIB": lib_yaml,
01044                               "RTCEXE": rtcexe_yaml, "RTCDLL": rtcdll_yaml}
01045 
01046     def load_yamls(self, yfiles):
01047         text = ""
01048         for f in yfiles:
01049             fd = open(f, "r")
01050             text += fd.read()
01051             fd.close()
01052         return text
01053 
01054     def replace_uuid(self, text):
01055         import uuid
01056         token0 = text.split("__GUID__")
01057         text0 = token0[0]
01058         for i in range(1, len(token0)):
01059             u = str(uuid.uuid1()).upper()
01060             text0 += u + token0[i]
01061     
01062         token1 = text0.split("__UUID")
01063         text1 = token1[0]
01064         for i in range(1, len(token1)):
01065             u = "_" + str(uuid.uuid1()).replace("-", "")
01066             text1 += u + token1[i]
01067         return text1
01068 
01069     def generate(self):
01070         text = ""
01071         loaded = ""
01072         if self.flist.has_key("yaml") and len(self.flist["yaml"]) > 0:
01073             loaded = self.load_yamls(self.flist["yaml"])
01074 
01075         if loaded.find("ProjectType:") < 0: # No toplevel config
01076             if self.yaml_template.has_key(self.type):
01077                 text = self.yaml_template[self.type]
01078                 text += loaded
01079             else:
01080                 print "type should be specified."
01081                 usage()
01082         else:
01083             text = loaded
01084 
01085         print self.flist
01086 
01087         text += FileList(self.flist).generate()
01088 
01089         text = self.replace_uuid(text)
01090         if self.projectname:
01091             text = text.replace("__PROJECT_NAME__", self.projectname)
01092         if self.version:
01093             text = text.replace("__VERSION__", self.version)
01094         if self.vcversion:
01095             text = text.replace("__VCVERSION__", self.vcversion)
01096         return text
01097 
01098 #------------------------------------------------------------
01099 # File list yaml file generator
01100 #------------------------------------------------------------
01101 class FileList:
01102     def __init__(self, flist):
01103         self.flist = flist
01104         self.filter = {"source":
01105                       {"Id": "Source",
01106                        "name": "Source Files",
01107                        "filter": "cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx",
01108                        },
01109                   "header":
01110                       {"Id": "Header",
01111                        "name": "Header Files",
01112                        "filter": "h;hpp;hxx;hm;inl;inc;xsd",
01113                        },
01114                   "resource":
01115                       {"Id": "Resoruce",
01116                        "name": "Resource Files",
01117                        "filter": "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav",
01118                        }
01119                   }
01120         self.temp = """%s:
01121   Name: %s
01122   Filter: %s
01123   GUID: __GUID__
01124   Files:
01125 """
01126         return
01127 
01128     def generate(self):
01129         text = ""
01130         for f in ["source", "header", "resource"]:
01131             if len(self.flist[f]) > 0:
01132                 text += self.temp % \
01133                     (self.filter[f]["Id"], self.filter[f]["name"],
01134                      self.filter[f]["filter"])
01135                 for file in self.flist[f]:
01136                     # vcproj's path delimiter should be "\"
01137                     file = file.replace("/","\\")
01138                     text += "    - Path: " + file + "\n"
01139         return text
01140 
01141 
01142 
01143            
01144 
01145 #def generate_vcproj(type, projectname, version, flist):
01146 #    yaml_text = ""
01147 #    for f in flist["yaml"]:
01148 #        fd = open(f, "r")
01149 #        yaml_text += fd.read()
01150 #        fd.close()
01151 #    yaml_text += generate_flist(flist)
01152 #    yaml_text = replace_uuid(yaml_text)
01153 #    if projectname:
01154 #        yaml_text = yaml_text.replace("__PROJECT_NAME__", projectname)
01155 #    if version:
01156 #        yaml_text = yaml_text.replace("__VERSION__", version)
01157 #    vcproj = VCProject(type, yaml_text)
01158 #    return vcproj.generate()
01159 #
01160 # 
01161 #
01162 #
01163 #def generate_yaml(type, projectname, version, flist):
01164 #    yaml_template = {"EXE": exe_yaml, "DLL": dll_yaml, "LIB": lib_yaml}
01165 #    text = yaml_template[type]
01166 #    text += generate_flist(flist)
01167 #    if projectname:
01168 #        text = text.replace("__PROJECT_NAME__", projectname)
01169 #    if version:
01170 #        text = text.replace("__VERSION__", version)
01171 #    return text
01172 
01173 #------------------------------------------------------------
01174 # command option
01175 #------------------------------------------------------------
01176 def parse_args(argv):
01177     cmd = argv[0]
01178     if not (cmd == "vcxproj" or cmd == "flist" or cmd == "yaml"):
01179         raise InvalidCommand("no such command: " + cmd)
01180         
01181     outfname = None
01182     type = None
01183     vcversion = None
01184     projectname = None
01185     version = None
01186     flist = {"yaml": [], "source": [], "header": [], "resource": []}
01187     i = 1
01188     argc = len(argv)
01189 
01190     while i < argc:
01191         opt = argv[i]
01192         if opt == "--projectname":
01193             i += 1
01194             if i < argc: projectname = argv[i]
01195             else: raise InvalidOption(opt + " needs value")
01196         elif opt == "--version":
01197             i += 1
01198             if i < argc: version = argv[i]
01199             else: raise InvalidOption(opt + " needs value")
01200         elif opt == "--vcversion":
01201             i += 1
01202             if i < argc: vcversion = argv[i]
01203             else: raise InvalidOption(opt + " needs value")
01204         elif opt == "--output" or opt == "--out" or opt == "-o":
01205             i += 1
01206             if i < argc: outfname = argv[i]
01207             else: raise InvalidOption(opt + " needs value")
01208         elif opt == "--type" or opt == "-t":
01209             i += 1
01210             if i < argc: type = argv[i]
01211             else: raise InvalidOption(opt + " needs value")
01212             type = type.upper()
01213             if not conf_type.has_key(type):
01214                 raise InvalidOption("unknown type: "
01215                                     + type + "\n" +
01216                                     "    --type should be [exe|dll|nmake|lib]")
01217         elif opt[:2] == "--" and flist.has_key(opt[2:]):
01218             lname = opt[2:]
01219             i += 1
01220             if not i < argc: raise InvalidOption(opt + " need value") 
01221             while i < argc and argv[i][:2] != "--":
01222                 flist[lname].append(argv[i])
01223                 i += 1
01224             if len(flist[lname]) == 0:
01225                 raise InvalidOption(opt + " needs value")
01226             i -= 1
01227         else:
01228             raise InvalidOption("unknown option: " + opt)
01229         i += 1
01230     return (cmd, vcversion, projectname, version, outfname, type, flist)
01231 
01232 #------------------------------------------------------------
01233 # main function
01234 #------------------------------------------------------------
01235 def main(argv):
01236     if len(argv) == 0:
01237         usage()
01238         sys.exit(-1)
01239 
01240     try:
01241         res = parse_args(argv)
01242     except VCProjException, e:
01243         print "\n" + e.msg + "\n"
01244         usage()
01245         sys.exit(-1)
01246 
01247     cmd = res[0]
01248     vcversion = res[1]
01249     projectname = res[2]
01250     version = res[3]
01251     outfile = res[4]
01252     type = res[5]
01253     flist = res[6]
01254 
01255     if cmd == "vcxproj":
01256         t = VCProject(type,
01257                       YamlConfig(type, vcversion,
01258                                  projectname, version, flist).generate()
01259                       ).generate()
01260     elif cmd == "flist":
01261         t = FileList(flist).generate()
01262     elif cmd == "yaml":
01263         t = YamlConfig(type, vcversion, projectname, version, flist).generate()
01264 
01265     if outfile == None:
01266         fd = sys.stdout
01267     else:
01268         fd = open(outfile, "wb")
01269 
01270     fd.write(t)
01271         
01272 #------------------------------------------------------------
01273 # tests
01274 #------------------------------------------------------------
01275 def test_filelist():
01276     print FileList({"source": ["hoge.cpp", "hage.cpp", "fuga.cpp"],
01277                     "header": ["hoge.h", "hage.h", "fuga.h"],
01278                     "resource": []}).generate()
01279 
01280 def test_yamlconfig():
01281     print YamlConfig("EXE", "10.00", "Test", "0.9.1",
01282                      {"source":
01283                           ["hoge.cpp",
01284                            "hage.cpp",
01285                            "fuga.cpp"],
01286                       "header":
01287                           ["hoge.h", "hage.h", "fuga.h"],
01288                       "resource":
01289                           []}).generate()
01290 
01291 def test_vcproj():
01292     print VCProject("EXE", YamlConfig("EXE", "10.00", "Test", "1.0.0",
01293                                       {"source":
01294                                            ["hoge.cpp",
01295                                             "hage.cpp",
01296                                             "fuga.cpp"],
01297                                        "header":
01298                                            ["hoge.h", "hage.h", "fuga.h"],
01299                                        "resource":
01300                                           [],
01301                                        "yaml":
01302                                            []}).generate()).generate()
01303 
01304 #------------------------------------------------------------
01305 # entry point
01306 #------------------------------------------------------------
01307 if __name__ == "__main__":
01308 #    test_filelist()
01309 #    test_yamlconfig()
01310 #    test_vcproj()
01311     main(sys.argv[1:])
01312     


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sun Mar 26 2017 03:37:17