msvc_sln_generator.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:14k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: msvc_sln_generator.cpp,v $
  4.  * PRODUCTION Revision 1000.2  2004/06/01 18:31:14  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.18
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /* $Id: msvc_sln_generator.cpp,v 1000.2 2004/06/01 18:31:14 gouriano Exp $
  10.  * ===========================================================================
  11.  *
  12.  *                            PUBLIC DOMAIN NOTICE
  13.  *               National Center for Biotechnology Information
  14.  *
  15.  *  This software/database is a "United States Government Work" under the
  16.  *  terms of the United States Copyright Act.  It was written as part of
  17.  *  the author's official duties as a United States Government employee and
  18.  *  thus cannot be copyrighted.  This software/database is freely available
  19.  *  to the public for use. The National Library of Medicine and the U.S.
  20.  *  Government have not placed any restriction on its use or reproduction.
  21.  *
  22.  *  Although all reasonable efforts have been taken to ensure the accuracy
  23.  *  and reliability of the software and data, the NLM and the U.S.
  24.  *  Government do not and cannot warrant the performance or results that
  25.  *  may be obtained by using this software or data. The NLM and the U.S.
  26.  *  Government disclaim all warranties, express or implied, including
  27.  *  warranties of performance, merchantability or fitness for any particular
  28.  *  purpose.
  29.  *
  30.  *  Please cite the author in any work or product based on this material.
  31.  *
  32.  * ===========================================================================
  33.  *
  34.  * Author:  Viatcheslav Gorelenkov
  35.  *
  36.  */
  37. #include <ncbi_pch.hpp>
  38. #include <app/project_tree_builder/stl_msvc_usage.hpp>
  39. #include <app/project_tree_builder/msvc_sln_generator.hpp>
  40. #include <app/project_tree_builder/msvc_prj_utils.hpp>
  41. #include <corelib/ncbifile.hpp>
  42. #include <corelib/ncbistr.hpp>
  43. #include <app/project_tree_builder/proj_builder_app.hpp>
  44. #include <app/project_tree_builder/msvc_prj_defines.hpp>
  45. #include <app/project_tree_builder/msvc_makefile.hpp>
  46. BEGIN_NCBI_SCOPE
  47. //-----------------------------------------------------------------------------
  48. CMsvcSolutionGenerator::CMsvcSolutionGenerator
  49.                                             (const list<SConfigInfo>& configs)
  50.     :m_Configs(configs)
  51. {
  52. }
  53. CMsvcSolutionGenerator::~CMsvcSolutionGenerator(void)
  54. {
  55. }
  56. void 
  57. CMsvcSolutionGenerator::AddProject(const CProjItem& project)
  58. {
  59.     m_Projects[CProjKey(project.m_ProjType, 
  60.                         project.m_ID)] = CPrjContext(project);
  61. }
  62. void 
  63. CMsvcSolutionGenerator::AddUtilityProject(const string& full_path)
  64. {
  65.     m_UtilityProjects.push_back(TUtilityProject(full_path, 
  66.                                                 GenerateSlnGUID()));
  67. }
  68. void 
  69. CMsvcSolutionGenerator::AddBuildAllProject(const string& full_path)
  70. {
  71.     m_BuildAllProject = TUtilityProject(full_path, GenerateSlnGUID());
  72. }
  73. void 
  74. CMsvcSolutionGenerator::SaveSolution(const string& file_path)
  75. {
  76.     CDirEntry::SplitPath(file_path, &m_SolutionDir);
  77.     // Create dir for output sln file
  78.     CDir(m_SolutionDir).CreatePath();
  79.     CNcbiOfstream  ofs(file_path.c_str(), IOS_BASE::out | IOS_BASE::trunc);
  80.     if ( !ofs )
  81.         NCBI_THROW(CProjBulderAppException, eFileCreation, file_path);
  82.     // Start sln file
  83.     ofs << MSVC_SOLUTION_HEADER_LINE << endl;
  84.     // Utility projects
  85.     ITERATE(list<TUtilityProject>, p, m_UtilityProjects) {
  86.         const TUtilityProject& utl_prj = *p;
  87.         WriteUtilityProject(utl_prj, ofs);
  88.     }
  89.     // BuildAll project
  90.     if ( !m_BuildAllProject.first.empty() &&
  91.         !m_BuildAllProject.second.empty() ) {
  92.         WriteBuildAllProject(m_BuildAllProject, ofs);
  93.     }
  94.     // Projects from the projects tree
  95.     ITERATE(TProjects, p, m_Projects) {
  96.         
  97.         WriteProjectAndSection(ofs, p->second);
  98.     }
  99.     // Start "Global" section
  100.     ofs << "Global" << endl;
  101.     // Write all configurations
  102.     ofs << 't' << "GlobalSection(SolutionConfiguration) = preSolution" << endl;
  103.     ITERATE(list<SConfigInfo>, p, m_Configs) {
  104.         const string& config = (*p).m_Name;
  105.         ofs << 't' << 't' << config << " = " << config << endl;
  106.     }
  107.     ofs << 't' << "EndGlobalSection" << endl;
  108.     
  109.     ofs << 't' 
  110.         << "GlobalSection(ProjectConfiguration) = postSolution" 
  111.         << endl;
  112.     // Utility projects
  113.     ITERATE(list<TUtilityProject>, p, m_UtilityProjects) {
  114.         const TUtilityProject& utl_prj = *p;
  115.         WriteUtilityProjectConfiguration(utl_prj, ofs);
  116.     }
  117.     // BuildAll project
  118.     if ( !m_BuildAllProject.first.empty() &&
  119.         !m_BuildAllProject.second.empty() ) {
  120.         WriteUtilityProjectConfiguration(m_BuildAllProject, ofs);
  121.     }
  122.     // Projects from tree
  123.     ITERATE(TProjects, p, m_Projects) {
  124.         
  125.         WriteProjectConfigurations(ofs, p->second);
  126.     }
  127.     ofs << 't' << "EndGlobalSection" << endl;
  128.     // meanless stuff
  129.     ofs << 't' 
  130.         << "GlobalSection(ExtensibilityGlobals) = postSolution" << endl;
  131. ofs << 't' << "EndGlobalSection" << endl;
  132. ofs << 't' << "GlobalSection(ExtensibilityAddIns) = postSolution" << endl;
  133. ofs << 't' << "EndGlobalSection" << endl;
  134.    
  135.     //End of global section
  136.     ofs << "EndGlobal" << endl;
  137. }
  138. //------------------------------------------------------------------------------
  139. CMsvcSolutionGenerator::CPrjContext::CPrjContext(void)
  140. {
  141.     Clear();
  142. }
  143. CMsvcSolutionGenerator::CPrjContext::CPrjContext(const CPrjContext& context)
  144. {
  145.     SetFrom(context);
  146. }
  147. CMsvcSolutionGenerator::CPrjContext::CPrjContext(const CProjItem& project)
  148.     :m_Project(project)
  149. {
  150.     m_GUID = GenerateSlnGUID();
  151.     CMsvcPrjProjectContext project_context(project);
  152.     if (project.m_ProjType == CProjKey::eMsvc) {
  153.         m_ProjectName = project_context.ProjectName();
  154.         string project_rel_path = project.m_Sources.front();
  155.         m_ProjectPath = CDirEntry::ConcatPath(project.m_SourcesBaseDir, 
  156.                                              project_rel_path);
  157.         m_ProjectPath = CDirEntry::NormalizePath(m_ProjectPath);
  158.     } else {
  159.         m_ProjectName = project_context.ProjectName();
  160.         m_ProjectPath = CDirEntry::ConcatPath(project_context.ProjectDir(),
  161.                                               project_context.ProjectName());
  162.         m_ProjectPath += MSVC_PROJECT_FILE_EXT;
  163.     }
  164. }
  165. CMsvcSolutionGenerator::CPrjContext& 
  166. CMsvcSolutionGenerator::CPrjContext::operator= (const CPrjContext& context)
  167. {
  168.     if (this != &context) {
  169.         Clear();
  170.         SetFrom(context);
  171.     }
  172.     return *this;
  173. }
  174. CMsvcSolutionGenerator::CPrjContext::~CPrjContext(void)
  175. {
  176.     Clear();
  177. }
  178. void 
  179. CMsvcSolutionGenerator::CPrjContext::Clear(void)
  180. {
  181.     //TODO
  182. }
  183. void 
  184. CMsvcSolutionGenerator::CPrjContext::SetFrom
  185.     (const CPrjContext& project_context)
  186. {
  187.     m_Project     = project_context.m_Project;
  188.     m_GUID        = project_context.m_GUID;
  189.     m_ProjectName = project_context.m_ProjectName;
  190.     m_ProjectPath = project_context.m_ProjectPath;
  191. }
  192. void 
  193. CMsvcSolutionGenerator::WriteProjectAndSection(CNcbiOfstream&     ofs, 
  194.                                                const CPrjContext& project)
  195. {
  196.     ofs << "Project("" 
  197.         << MSVC_SOLUTION_ROOT_GUID 
  198.         << "") = "" 
  199.         << project.m_ProjectName 
  200.         << "", "";
  201.     ofs << CDirEntry::CreateRelativePath(m_SolutionDir, project.m_ProjectPath)
  202.         << "", "";
  203.     ofs << project.m_GUID 
  204.         << """ 
  205.         << endl;
  206.     ofs << 't' << "ProjectSection(ProjectDependencies) = postProject" << endl;
  207.     ITERATE(list<CProjKey>, p, project.m_Project.m_Depends) {
  208.         const CProjKey& id = *p;
  209.         // Do not generate lib-to-lib depends.
  210.         if (project.m_Project.m_ProjType == CProjKey::eLib  &&
  211.             id.Type() == CProjKey::eLib) {
  212.             continue;
  213.         }
  214.         // Do not generate dependencies if internal lib
  215.         // is present in form of 3-rd party lib
  216.         if (id.Type() == CProjKey::eLib                  &&
  217.             GetApp().GetSite().IsLibWithChoice(id.Id())  &&
  218.             GetApp().GetSite().GetChoiceForLib(id.Id()) == CMsvcSite::e3PartyLib) {
  219.             continue;
  220.         }
  221.         TProjects::const_iterator n = m_Projects.find(id);
  222.         if (n != m_Projects.end()) {
  223.             const CPrjContext& prj_i = n->second;
  224.             ofs << 't' << 't' 
  225.                 << prj_i.m_GUID 
  226.                 << " = " 
  227.                 << prj_i.m_GUID << endl;
  228.         } else {
  229.             LOG_POST(Warning << "Project: " + 
  230.                       project.m_ProjectName + " is dependend of " + id.Id() + 
  231.                       ". But no such project");
  232.         }
  233.     }
  234.     ofs << 't' << "EndProjectSection" << endl;
  235.     ofs << "EndProject" << endl;
  236. }
  237. void 
  238. CMsvcSolutionGenerator::WriteUtilityProject(const TUtilityProject& project,
  239.                                             CNcbiOfstream&         ofs)
  240. {
  241.     ofs << "Project("" 
  242.         << MSVC_SOLUTION_ROOT_GUID
  243.         << "") = "" 
  244.         << CDirEntry(project.first).GetBase() //basename
  245.         << "", "";
  246.     ofs << CDirEntry::CreateRelativePath(m_SolutionDir, 
  247.                                          project.first)
  248.         << "", "";
  249.     ofs << project.second //m_GUID 
  250.         << """ 
  251.         << endl;
  252.     ofs << 't' << "ProjectSection(ProjectDependencies) = postProject" << endl;
  253.     ofs << 't' << "EndProjectSection" << endl;
  254.     ofs << "EndProject" << endl;
  255. }
  256. void 
  257. CMsvcSolutionGenerator::WriteBuildAllProject(const TUtilityProject& project, 
  258.                                              CNcbiOfstream&         ofs)
  259. {
  260.     ofs << "Project("" 
  261.         << MSVC_SOLUTION_ROOT_GUID 
  262.         << "") = "" 
  263.         << CDirEntry(project.first).GetBase() //basename 
  264.         << "", "";
  265.     ofs << CDirEntry::CreateRelativePath(m_SolutionDir, 
  266.                                          project.first)
  267.         << "", "";
  268.     ofs << project.second // m_GUID 
  269.         << """ 
  270.         << endl;
  271.     ofs << 't' << "ProjectSection(ProjectDependencies) = postProject" << endl;
  272.     
  273.     ITERATE(TProjects, p, m_Projects) {
  274.         const CProjKey&    id    = p->first;
  275.         const CPrjContext& prj_i = p->second;
  276.         ofs << 't' << 't' 
  277.             << prj_i.m_GUID 
  278.             << " = " 
  279.             << prj_i.m_GUID << endl;
  280.     }
  281.     ofs << 't' << "EndProjectSection" << endl;
  282.     ofs << "EndProject" << endl;
  283. }
  284. void 
  285. CMsvcSolutionGenerator::WriteProjectConfigurations(CNcbiOfstream&     ofs, 
  286.                                                    const CPrjContext& project)
  287. {
  288.     ITERATE(list<SConfigInfo>, p, m_Configs) {
  289.         const SConfigInfo& cfg_info = *p;
  290.         CMsvcPrjProjectContext context(project.m_Project);
  291.         
  292.         bool config_enabled = context.IsConfigEnabled(cfg_info);
  293.         const string& config = cfg_info.m_Name;
  294.         
  295.         ofs << 't' 
  296.             << 't' 
  297.             << project.m_GUID 
  298.             << '.' 
  299.             << config 
  300.             << ".ActiveCfg = " 
  301.             << ConfigName(config)
  302.             << endl;
  303.         ofs << 't' 
  304.             << 't' 
  305.             << project.m_GUID 
  306.             << '.' 
  307.             << config 
  308.             << ".Build.0 = " 
  309.             << ConfigName(config)
  310.             << endl;
  311.     }
  312. }
  313. void 
  314. CMsvcSolutionGenerator::WriteUtilityProjectConfiguration(const TUtilityProject& project,
  315.                                                         CNcbiOfstream& ofs)
  316. {
  317.     ITERATE(list<SConfigInfo>, p, m_Configs) {
  318.         const string& config = (*p).m_Name;
  319.         ofs << 't' 
  320.             << 't' 
  321.             << project.second // project.m_GUID 
  322.             << '.' 
  323.             << config 
  324.             << ".ActiveCfg = " 
  325.             << ConfigName(config)
  326.             << endl;
  327.         ofs << 't' 
  328.             << 't' 
  329.             << project.second // project.m_GUID 
  330.             << '.' 
  331.             << config 
  332.             << ".Build.0 = " 
  333.             << ConfigName(config)
  334.             << endl;
  335.     }
  336. }
  337. END_NCBI_SCOPE
  338. /*
  339.  * ===========================================================================
  340.  * $Log: msvc_sln_generator.cpp,v $
  341.  * Revision 1000.2  2004/06/01 18:31:14  gouriano
  342.  * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.18
  343.  *
  344.  * Revision 1.18  2004/05/21 21:41:41  gorelenk
  345.  * Added PCH ncbi_pch.hpp
  346.  *
  347.  * Revision 1.17  2004/05/10 19:51:16  gorelenk
  348.  * Changed CMsvcSolutionGenerator::WriteProjectAndSection .
  349.  *
  350.  * Revision 1.16  2004/04/19 15:42:56  gorelenk
  351.  * Changed implementation of CMsvcSolutionGenerator::WriteProjectAndSection :
  352.  * added test for lib choice.
  353.  *
  354.  * Revision 1.15  2004/02/25 19:45:00  gorelenk
  355.  * +BuildAll utility project.
  356.  *
  357.  * Revision 1.14  2004/02/24 23:26:17  gorelenk
  358.  * Changed implementation  of member-function WriteProjectConfigurations
  359.  * of class CMsvcSolutionGenerator.
  360.  *
  361.  * Revision 1.13  2004/02/24 21:15:31  gorelenk
  362.  * Added test for config availability for project to implementation  of
  363.  * member-function WriteProjectConfigurations of class CMsvcSolutionGenerator.
  364.  *
  365.  * Revision 1.12  2004/02/20 22:53:26  gorelenk
  366.  * Added analysis of ASN projects depends.
  367.  *
  368.  * Revision 1.11  2004/02/12 23:15:29  gorelenk
  369.  * Implemented utility projects creation and configure re-build of the app.
  370.  *
  371.  * Revision 1.10  2004/02/12 17:45:12  gorelenk
  372.  * Redesigned projects saving.
  373.  *
  374.  * Revision 1.9  2004/02/12 16:27:58  gorelenk
  375.  * Changed generation of command line for datatool.
  376.  *
  377.  * Revision 1.8  2004/02/10 18:20:16  gorelenk
  378.  * Changed LOG_POST messages.
  379.  *
  380.  * Revision 1.7  2004/02/05 00:00:48  gorelenk
  381.  * Changed log messages generation.
  382.  *
  383.  * Revision 1.6  2004/01/28 17:55:49  gorelenk
  384.  * += For msvc makefile support of :
  385.  *                 Requires tag, ExcludeProject tag,
  386.  *                 AddToProject section (SourceFiles and IncludeDirs),
  387.  *                 CustomBuild section.
  388.  * += For support of user local site.
  389.  *
  390.  * Revision 1.5  2004/01/26 19:27:29  gorelenk
  391.  * += MSVC meta makefile support
  392.  * += MSVC project makefile support
  393.  *
  394.  * Revision 1.4  2004/01/22 17:57:54  gorelenk
  395.  * first version
  396.  *
  397.  * ===========================================================================
  398.  */