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

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: proj_builder_app.cpp,v $
  4.  * PRODUCTION Revision 1000.4  2004/06/16 17:02:36  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.43
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. /* $Id: proj_builder_app.cpp,v 1000.4 2004/06/16 17:02:36 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/proj_builder_app.hpp>
  39. #include <app/project_tree_builder/proj_item.hpp>
  40. #include <app/project_tree_builder/proj_tree_builder.hpp>
  41. #include <app/project_tree_builder/msvc_prj_utils.hpp>
  42. #include <app/project_tree_builder/msvc_prj_generator.hpp>
  43. #include <app/project_tree_builder/msvc_sln_generator.hpp>
  44. #include <app/project_tree_builder/msvc_masterproject_generator.hpp>
  45. #include <app/project_tree_builder/proj_utils.hpp>
  46. #include <app/project_tree_builder/msvc_configure.hpp>
  47. #include <app/project_tree_builder/msvc_prj_defines.hpp>
  48. #include <app/project_tree_builder/msvc_configure_prj_generator.hpp>
  49. #include <app/project_tree_builder/proj_projects.hpp>
  50. #include <corelib/ncbitime.hpp>
  51. BEGIN_NCBI_SCOPE
  52. #ifdef COMBINED_EXCLUDE
  53. struct PIsExcludedByProjectMakefile
  54. {
  55.     typedef CProjectItemsTree::TProjects::value_type TValueType;
  56.     bool operator() (const TValueType& item) const
  57.     {
  58.         const CProjItem& project = item.second;
  59.         CMsvcPrjProjectContext prj_context(project);
  60.         const list<string> implicit_exclude_dirs = 
  61.             GetApp().GetProjectTreeInfo().m_ImplicitExcludedAbsDirs;
  62.         ITERATE(list<string>, p, implicit_exclude_dirs) {
  63.             const string& dir = *p;
  64.             if ( IsSubdir(dir, project.m_SourcesBaseDir) ) {
  65.                 // implicitly excluded from build
  66.                 return prj_context.GetMsvcProjectMakefile().IsExcludeProject
  67.                                                                         (true);
  68.             }
  69.         }
  70.         // implicitly included to build
  71.         return prj_context.GetMsvcProjectMakefile().IsExcludeProject(false);
  72.     }
  73. };
  74. struct PIsExcludedMakefileIn
  75. {
  76.     typedef CProjectItemsTree::TProjects::value_type TValueType;
  77.     PIsExcludedMakefileIn(const string& root_src_dir)
  78.         :m_RootSrcDir(CDirEntry::NormalizePath(root_src_dir))
  79.     {
  80.         ProcessDir(root_src_dir);
  81.     }
  82.     bool operator() (const TValueType& item) const
  83.     {
  84.         const CProjItem& project = item.second;
  85.         const list<string> implicit_exclude_dirs = 
  86.             GetApp().GetProjectTreeInfo().m_ImplicitExcludedAbsDirs;
  87.         ITERATE(list<string>, p, implicit_exclude_dirs) {
  88.             const string& dir = *p;
  89.             if ( IsSubdir(dir, project.m_SourcesBaseDir) ) {
  90.                 // implicitly excluded from build
  91.                 return !IsExcplicitlyIncluded(project.m_SourcesBaseDir);
  92.             }
  93.         }
  94.         return false;
  95.     }
  96. private:
  97.     string m_RootSrcDir;
  98.     typedef map<string, AutoPtr<CNcbiRegistry> > TMakefiles;
  99.     TMakefiles m_Makefiles;
  100.     void ProcessDir(const string& dir_name)
  101.     {
  102.         CDir dir(dir_name);
  103.         CDir::TEntries contents = dir.GetEntries("*");
  104.         ITERATE(CDir::TEntries, i, contents) {
  105.             string name  = (*i)->GetName();
  106.             if ( name == "."  ||  name == ".."  ||  
  107.                  name == string(1,CDir::GetPathSeparator()) ) {
  108.                 continue;
  109.             }
  110.             string path = (*i)->GetPath();
  111.             if ( (*i)->IsFile()        &&
  112.                 name          == "Makefile.in.msvc" ) {
  113.                 m_Makefiles[path] = 
  114.                     AutoPtr<CNcbiRegistry>
  115.                          (new CNcbiRegistry(CNcbiIfstream(path.c_str(), 
  116.                                             IOS_BASE::in | IOS_BASE::binary)));
  117.             } 
  118.             else if ( (*i)->IsDir() ) {
  119.                 ProcessDir(path);
  120.             }
  121.         }
  122.     }
  123.     bool IsExcplicitlyIncluded(const string& project_base_dir) const
  124.     {
  125.         string dir = project_base_dir;
  126.         for(;;) {
  127.             if (dir == m_RootSrcDir) 
  128.                 return false;
  129.             string path = CDirEntry::ConcatPath(dir, "Makefile.in.msvc");
  130.             TMakefiles::const_iterator p = 
  131.                 m_Makefiles.find(path);
  132.             if ( p != m_Makefiles.end() ) {
  133.                 string val = 
  134.                     (p->second)->GetString("Common", "ExcludeProject", "");
  135.                 if (val == "FALSE")
  136.                     return true;
  137.             }
  138.             dir = CDirEntry::ConcatPath(dir, "..");
  139.             dir = CDirEntry::NormalizePath(dir);
  140.         }
  141.         return false;
  142.     }
  143. };
  144. template <class T1, class T2, class V> class CCombine
  145. {
  146. public:
  147.     CCombine(const T1& t1, const T2& t2)
  148.         :m_T1(t1), m_T2(t2)
  149.     {
  150.     }
  151.     bool operator() (const V& v) const
  152.     {
  153.         return m_T1(v)  &&  m_T2(v);
  154.     }
  155. private:
  156.     const T1 m_T1;
  157.     const T2 m_T2;
  158. };
  159. #else
  160. // not def COMBINED_EXCLUDE
  161. struct PIsExcludedByProjectMakefile
  162. {
  163.     typedef CProjectItemsTree::TProjects::value_type TValueType;
  164.     bool operator() (const TValueType& item) const
  165.     {
  166.         const CProjItem& project = item.second;
  167.         CMsvcPrjProjectContext prj_context(project);
  168.         const list<string> implicit_exclude_dirs = 
  169.             GetApp().GetProjectTreeInfo().m_ImplicitExcludedAbsDirs;
  170.         ITERATE(list<string>, p, implicit_exclude_dirs) {
  171.             const string& dir = *p;
  172.             if ( IsSubdir(dir, project.m_SourcesBaseDir) ) {
  173.                 // implicitly excluded from build
  174.                 return prj_context.GetMsvcProjectMakefile().IsExcludeProject
  175.                                                                         (true);
  176.             }
  177.         }
  178.         // implicitly included to build
  179.         return prj_context.GetMsvcProjectMakefile().IsExcludeProject(false);
  180.     }
  181. };
  182. #endif
  183. struct PIsExcludedByRequires
  184. {
  185.     typedef CProjectItemsTree::TProjects::value_type TValueType;
  186.     bool operator() (const TValueType& item) const
  187.     {
  188.         const CProjItem& project = item.second;
  189.         if ( CMsvcPrjProjectContext::IsRequiresOk(project) )
  190.             return false;
  191.         return true;
  192.     }
  193. };
  194. //-----------------------------------------------------------------------------
  195. CProjBulderApp::CProjBulderApp(void)
  196. {
  197. }
  198. void CProjBulderApp::Init(void)
  199. {
  200.     // Create command-line argument descriptions class
  201.     auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
  202.     // Specify USAGE context
  203.     arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
  204.                               "MSVC 7.10 projects builder application");
  205.     // Programm arguments:
  206.     arg_desc->AddPositional("root",
  207.                             "Root directory of the build tree. "
  208.                                 "This directory ends with "c++".",
  209.                             CArgDescriptions::eString);
  210.     arg_desc->AddPositional("subtree",
  211.                             "Subtree to build. Example: src/corelib/ .",
  212.                             CArgDescriptions::eString);
  213.     arg_desc->AddPositional("solution", 
  214.                             "MSVC Solution to buld.",
  215.     CArgDescriptions::eString);
  216.     arg_desc->AddFlag      ("dll", 
  217.                             "Dll(s) will be buit instead of static libraries.",
  218.     true);
  219.     // Setup arg.descriptions for this application
  220.     SetupArgDescriptions(arg_desc.release());
  221. }
  222. static 
  223. void s_ReportDependenciesStatus(const CCyclicDepends::TDependsCycles& cycles)
  224. {
  225.    if ( cycles.empty() ) {
  226.         LOG_POST(Info << "Ok. No dependencies cycles found.");
  227.     } else {
  228.         ITERATE(CCyclicDepends::TDependsCycles, p, cycles) {
  229.             const CCyclicDepends::TDependsChain& cycle = *p;
  230.             LOG_POST(Error << "Dependencies cycle found :");
  231.             ITERATE(CCyclicDepends::TDependsChain, n, cycle) {
  232.                 const CProjKey& proj_id = *n;
  233.                 LOG_POST(Error << "Cycle with project :" + proj_id.Id());
  234.             }
  235.         }
  236.     }
  237. }
  238. int CProjBulderApp::Run(void)
  239. {
  240.     // Get and check arguments
  241.     ParseArguments();
  242. // Set error posting and tracing on maximum.
  243. SetDiagTrace(eDT_Enable);
  244. SetDiagPostFlag(eDPF_Default);
  245. SetDiagPostLevel(eDiag_Info);
  246.     // Start 
  247.     LOG_POST(Info << "Started at " + CTime(CTime::eCurrent).AsString());
  248.     // Configure 
  249.     CMsvcConfigure configure;
  250.     configure(GetSite(), 
  251.               GetRegSettings().m_ConfigInfo, 
  252.               GetProjectTreeInfo().m_Root);
  253.     // Build projects tree
  254.     CProjectItemsTree projects_tree(GetProjectTreeInfo().m_Src);
  255.     CProjectTreeBuilder::BuildProjectTree(GetProjectTreeInfo().m_IProjectFilter.get(), 
  256.                                           GetProjectTreeInfo().m_Src, 
  257.                                           &projects_tree);
  258.     
  259.     // Analyze tree for dependencies cycles
  260.     LOG_POST(Info << "Checking projects inter-dependencies... .");
  261.     CCyclicDepends::TDependsCycles cycles;
  262.     CCyclicDepends::FindCycles(projects_tree.m_Projects, &cycles);
  263.     s_ReportDependenciesStatus(cycles);
  264.     // MSVC specific part:
  265.     
  266.     // Exclude some projects from build:
  267. #ifdef COMBINED_EXCLUDE
  268.     {{
  269.         // Implicit/Exclicit exclude by msvc Makefiles.in.msvc
  270.         // and project .msvc makefiles.
  271.         PIsExcludedMakefileIn          p_make_in(GetProjectTreeInfo().m_Src);
  272.         PIsExcludedByProjectMakefile   p_project_makefile;
  273.         CCombine<PIsExcludedMakefileIn, 
  274.                  PIsExcludedByProjectMakefile,  
  275.                  CProjectItemsTree::TProjects::value_type> 
  276.                                   logical_combine(p_make_in, p_project_makefile);
  277.         EraseIf(projects_tree.m_Projects, logical_combine);
  278.     }}
  279. #else
  280.     {{
  281.         // Implicit/Exclicit exclude by msvc Makefiles.in.msvc
  282.         PIsExcludedByProjectMakefile   p_project_makefile;
  283.         EraseIf(projects_tree.m_Projects, p_project_makefile);
  284.     }}
  285. #endif
  286.     {{
  287.         // Project requires are not provided
  288.         EraseIf(projects_tree.m_Projects, PIsExcludedByRequires());
  289.     }}
  290.     if (GetBuildType().GetType() == CBuildType::eStatic) {
  291.         
  292.         // Static build
  293.         
  294.         // Projects
  295.         CMsvcProjectGenerator prj_gen(GetRegSettings().m_ConfigInfo);
  296.         ITERATE(CProjectItemsTree::TProjects, p, projects_tree.m_Projects) {
  297.             prj_gen.Generate(p->second);
  298.         }
  299.         //Utility projects dir
  300.         string utility_projects_dir = CDirEntry(m_Solution).GetDir();
  301.         utility_projects_dir = 
  302.             CDirEntry::ConcatPath(utility_projects_dir, "UtilityProjects");
  303.         utility_projects_dir = 
  304.             CDirEntry::AddTrailingPathSeparator(utility_projects_dir);
  305.         // MasterProject
  306.         CMsvcMasterProjectGenerator master_prj_gen(projects_tree,
  307.                                                    GetRegSettings().m_ConfigInfo,
  308.                                                    utility_projects_dir);
  309.         master_prj_gen.SaveProject();
  310.         // ConfigureProject
  311.         string output_dir = GetProjectTreeInfo().m_Compilers;
  312.         output_dir = CDirEntry::ConcatPath(output_dir, 
  313.                                            GetRegSettings().m_CompilersSubdir);
  314.         output_dir = CDirEntry::ConcatPath(output_dir, 
  315.                                            GetBuildType().GetTypeStr());
  316.         output_dir = CDirEntry::ConcatPath(output_dir, "bin");
  317.         output_dir = CDirEntry::AddTrailingPathSeparator(output_dir);
  318.         CMsvcConfigureProjectGenerator configure_generator
  319.                                               (output_dir,
  320.                                                GetRegSettings().m_ConfigInfo,
  321.                                                false,
  322.                                                utility_projects_dir,
  323.                                                GetProjectTreeInfo().m_Root,
  324.                                                GetArgs()["subtree"].AsString(),
  325.                                                m_Solution);
  326.         configure_generator.SaveProject();
  327.         // INDEX dummy project
  328.         CVisualStudioProject index_xmlprj;
  329.         CreateUtilityProject(" INDEX, see here: ", 
  330.                              GetRegSettings().m_ConfigInfo, 
  331.                              &index_xmlprj);
  332.         string index_prj_path = 
  333.             CDirEntry::ConcatPath(utility_projects_dir, "_INDEX_");
  334.         index_prj_path += MSVC_PROJECT_FILE_EXT;
  335.         SaveIfNewer(index_prj_path, index_xmlprj);
  336.         //
  337.         // BuildAll utility project
  338.         CVisualStudioProject build_all_xmlprj;
  339.         CreateUtilityProject("-BUILD-ALL-", 
  340.                              GetRegSettings().m_ConfigInfo, 
  341.                              &build_all_xmlprj);
  342.         string build_all_prj_path = 
  343.             CDirEntry::ConcatPath(utility_projects_dir, "_BUILD_ALL_");
  344.         build_all_prj_path += MSVC_PROJECT_FILE_EXT;
  345.         SaveIfNewer(build_all_prj_path, build_all_xmlprj);
  346.         //
  347.         // Solution
  348.         CMsvcSolutionGenerator sln_gen(GetRegSettings().m_ConfigInfo);
  349.         ITERATE(CProjectItemsTree::TProjects, p, projects_tree.m_Projects) {
  350.             sln_gen.AddProject(p->second);
  351.         }
  352.         sln_gen.AddUtilityProject (master_prj_gen.GetPath());
  353.         sln_gen.AddUtilityProject (configure_generator.GetPath());
  354.         sln_gen.AddUtilityProject (index_prj_path);
  355.         sln_gen.AddBuildAllProject(build_all_prj_path);
  356.         sln_gen.SaveSolution(m_Solution);
  357.     }
  358.     if (GetBuildType().GetType() == CBuildType::eDll) {
  359.         //Dll build
  360.         list<SConfigInfo> dll_configs;
  361.         GetDllsInfo().GetBuildConfigs(&dll_configs);
  362.         CProjectItemsTree dll_projects_tree;
  363.         CreateDllBuildTree(projects_tree, &dll_projects_tree);
  364.         // Projects
  365.         CMsvcProjectGenerator prj_gen(dll_configs);
  366.         ITERATE(CProjectItemsTree::TProjects, p, dll_projects_tree.m_Projects) {
  367.             prj_gen.Generate(p->second);
  368.         }
  369.         //Utility projects dir
  370.         string utility_projects_dir = CDirEntry(m_Solution).GetDir();
  371.         utility_projects_dir = 
  372.             CDirEntry::ConcatPath(utility_projects_dir, "UtilityProjects");
  373.         utility_projects_dir = 
  374.             CDirEntry::AddTrailingPathSeparator(utility_projects_dir);
  375.         // MasterProject
  376.         CMsvcMasterProjectGenerator master_prj_gen(dll_projects_tree,
  377.                                                    dll_configs,
  378.                                                    utility_projects_dir);
  379.         master_prj_gen.SaveProject();
  380.         // ConfigureProject
  381.         string output_dir = GetProjectTreeInfo().m_Compilers;
  382.         output_dir = CDirEntry::ConcatPath(output_dir, 
  383.                                            GetRegSettings().m_CompilersSubdir);
  384.         output_dir = CDirEntry::ConcatPath(output_dir, 
  385.                                            "static");
  386.         output_dir = CDirEntry::ConcatPath(output_dir, "bin");
  387.         output_dir = CDirEntry::AddTrailingPathSeparator(output_dir);
  388.         CMsvcConfigureProjectGenerator configure_generator
  389.                               (output_dir,
  390.                                dll_configs,
  391.                                true,
  392.                                utility_projects_dir,
  393.                                GetProjectTreeInfo().m_Root,
  394.                                GetArgs()["subtree"].AsString(),
  395.                                m_Solution);
  396.         configure_generator.SaveProject();
  397.         // INDEX dummy project
  398.         CVisualStudioProject index_xmlprj;
  399.         CreateUtilityProject(" INDEX, see here: ", 
  400.                              dll_configs, 
  401.                              &index_xmlprj);
  402.         string index_prj_path = 
  403.             CDirEntry::ConcatPath(utility_projects_dir, "_INDEX_");
  404.         index_prj_path += MSVC_PROJECT_FILE_EXT;
  405.         SaveIfNewer(index_prj_path, index_xmlprj);
  406.         //
  407.         // BuildAll utility project
  408.         CVisualStudioProject build_all_xmlprj;
  409.         CreateUtilityProject("-BUILD-ALL-", 
  410.                              dll_configs, 
  411.                              &build_all_xmlprj);
  412.         string build_all_prj_path = 
  413.             CDirEntry::ConcatPath(utility_projects_dir, "_BUILD_ALL_");
  414.         build_all_prj_path += MSVC_PROJECT_FILE_EXT;
  415.         SaveIfNewer(build_all_prj_path, build_all_xmlprj);
  416.         //
  417.         // Solution
  418.         CMsvcSolutionGenerator sln_gen(dll_configs);
  419.         ITERATE(CProjectItemsTree::TProjects, p, dll_projects_tree.m_Projects) {
  420.             sln_gen.AddProject(p->second);
  421.         }
  422.         sln_gen.AddUtilityProject (master_prj_gen.GetPath());
  423.         sln_gen.AddUtilityProject (configure_generator.GetPath());
  424.         sln_gen.AddUtilityProject (index_prj_path);
  425.         sln_gen.AddBuildAllProject(build_all_prj_path);
  426.         sln_gen.SaveSolution(m_Solution);
  427.     }
  428.     //
  429.     LOG_POST(Info << "Finished at "+ CTime(CTime::eCurrent).AsString());
  430.     return 0;
  431. }
  432. void CProjBulderApp::Exit(void)
  433. {
  434. //TODO
  435. }
  436. void CProjBulderApp::ParseArguments(void)
  437. {
  438.     CArgs args = GetArgs();
  439.     /// Root dir of building tree,
  440.     /// src child dir of Root,
  441.     /// Subtree to buil (default is m_RootSrc)
  442.     /// are provided by SProjectTreeInfo (see GetProjectTreeInfo(void) below)
  443.     // Solution
  444.     m_Solution = CDirEntry::NormalizePath(args["solution"].AsString());
  445. }
  446. int CProjBulderApp::EnumOpt(const string& enum_name, 
  447.                             const string& enum_val) const
  448. {
  449.     int opt = GetConfig().GetInt(enum_name, enum_val, -1);
  450.     if (opt == -1) {
  451.     NCBI_THROW(CProjBulderAppException, eEnumValue, 
  452.                                 enum_name + "::" + enum_val);
  453.     }
  454.     return opt;
  455. }
  456. void CProjBulderApp::DumpFiles(const TFiles& files, 
  457.    const string& filename) const
  458. {
  459.     CNcbiOfstream  ofs(filename.c_str(), IOS_BASE::out | IOS_BASE::trunc);
  460.     if ( !ofs ) {
  461.     NCBI_THROW(CProjBulderAppException, eFileCreation, filename);
  462.     }
  463.     ITERATE(TFiles, p, files) {
  464.     ofs << "+++++++++++++++++++++++++n";
  465.     ofs << p->first << endl;
  466.     p->second.Dump(ofs);
  467.     ofs << "-------------------------n";
  468.     }
  469. }
  470. void CProjBulderApp::GetMetaDataFiles(list<string>* files) const
  471. {
  472.     files->clear();
  473.     string files_str = GetConfig().GetString("ProjectTree", "MetaData", "");
  474.     NStr::Split(files_str, LIST_SEPARATOR, *files);
  475. }
  476. void CProjBulderApp::GetBuildConfigs(list<SConfigInfo>* configs) const
  477. {
  478.     configs->clear();
  479.     string config_str = GetConfig().GetString("msvc7", "Configurations", "");
  480.     list<string> configs_list;
  481.     NStr::Split(config_str, LIST_SEPARATOR, configs_list);
  482.     LoadConfigInfoByNames(GetConfig(), configs_list, configs);
  483. }
  484. const CMsvc7RegSettings& CProjBulderApp::GetRegSettings(void)
  485. {
  486.     if ( !m_MsvcRegSettings.get() ) {
  487.         m_MsvcRegSettings.reset(new CMsvc7RegSettings());
  488.     
  489.         m_MsvcRegSettings->m_Version = 
  490.             GetConfig().GetString("msvc7", "Version", "7.10");
  491.         GetBuildConfigs(&m_MsvcRegSettings->m_ConfigInfo);
  492.         m_MsvcRegSettings->m_CompilersSubdir  = 
  493.             GetConfig().GetString("msvc7", "compilers", "msvc710_prj");
  494.     
  495.         m_MsvcRegSettings->m_ProjectsSubdir  = 
  496.             GetConfig().GetString("msvc7", "Projects", "build");
  497.         m_MsvcRegSettings->m_MakefilesExt = 
  498.             GetConfig().GetString("msvc7", "MakefilesExt", "msvc");
  499.         m_MsvcRegSettings->m_MetaMakefile = 
  500.             GetConfig().GetString("msvc7", "MetaMakefile", "");
  501.         m_MsvcRegSettings->m_DllInfo = 
  502.             GetConfig().GetString("msvc7", "DllInfo", "");
  503.     }
  504.     return *m_MsvcRegSettings;
  505. }
  506. const CMsvcSite& CProjBulderApp::GetSite(void)
  507. {
  508.     if ( !m_MsvcSite.get() ) 
  509.         m_MsvcSite.reset(new CMsvcSite(GetConfig()));
  510.     
  511.     return *m_MsvcSite;
  512. }
  513. const CMsvcMetaMakefile& CProjBulderApp::GetMetaMakefile(void)
  514. {
  515.     if ( !m_MsvcMetaMakefile.get() ) {
  516.         //Metamakefile must be in RootSrc directory
  517.         m_MsvcMetaMakefile.reset(new CMsvcMetaMakefile
  518.                     (CDirEntry::ConcatPath(GetProjectTreeInfo().m_Src,
  519.                                            GetRegSettings().m_MetaMakefile)));
  520.         
  521.         //Metamakefile must present and must not be empty
  522.         if ( m_MsvcMetaMakefile->IsEmpty() )
  523.             NCBI_THROW(CProjBulderAppException, 
  524.                        eMetaMakefile, GetRegSettings().m_MetaMakefile);
  525.     }
  526.     return *m_MsvcMetaMakefile;
  527. }
  528. const SProjectTreeInfo& CProjBulderApp::GetProjectTreeInfo(void)
  529. {
  530.     if ( m_ProjectTreeInfo.get() )
  531.         return *m_ProjectTreeInfo;
  532.         
  533.     m_ProjectTreeInfo.reset(new SProjectTreeInfo);
  534.     
  535.     CArgs args = GetArgs();
  536.     
  537.     // Root, etc.
  538.     string root = args["root"].AsString();
  539.     root = CDirEntry::AddTrailingPathSeparator(root);
  540.     root = CDirEntry::NormalizePath(root);
  541.     root = CDirEntry::AddTrailingPathSeparator(root);
  542.     m_ProjectTreeInfo->m_Root = root;
  543.     /// <include> branch of tree
  544.     string include = GetConfig().GetString("ProjectTree", "include", "");
  545.     m_ProjectTreeInfo->m_Include = 
  546.             CDirEntry::ConcatPath(m_ProjectTreeInfo->m_Root, 
  547.                                   include);
  548.     m_ProjectTreeInfo->m_Include = 
  549.         CDirEntry::AddTrailingPathSeparator(m_ProjectTreeInfo->m_Include);
  550.     
  551.     /// <src> branch of tree
  552.     string src = GetConfig().GetString("ProjectTree", "src", "");
  553.     m_ProjectTreeInfo->m_Src = 
  554.             CDirEntry::ConcatPath(m_ProjectTreeInfo->m_Root, 
  555.                                   src);
  556.     m_ProjectTreeInfo->m_Src =
  557.         CDirEntry::AddTrailingPathSeparator(m_ProjectTreeInfo->m_Src);
  558.     // Subtree to build - projects filter
  559.     string subtree = args["subtree"].AsString();
  560.     subtree = 
  561.         CDirEntry::ConcatPath(m_ProjectTreeInfo->m_Root, subtree);
  562.     string ext;
  563.     CDirEntry::SplitPath(subtree, NULL, NULL, &ext);
  564.     if (NStr::CompareNocase(ext, ".lst") == 0) {
  565.         //If this is *.lst file
  566.         m_ProjectTreeInfo->m_IProjectFilter.reset
  567.             (new CProjectsLstFileFilter(m_ProjectTreeInfo->m_Src,
  568.                                         subtree));
  569.     } else {
  570.         //Simple subtree
  571.         subtree = CDirEntry::AddTrailingPathSeparator(subtree);
  572.         m_ProjectTreeInfo->m_IProjectFilter.reset
  573.             (new CProjectOneNodeFilter(m_ProjectTreeInfo->m_Src,
  574.                                         subtree));
  575.     }
  576.     /// <compilers> branch of tree
  577.     string compilers = 
  578.         GetConfig().GetString("ProjectTree", "compilers", "");
  579.     m_ProjectTreeInfo->m_Compilers = 
  580.             CDirEntry::ConcatPath(m_ProjectTreeInfo->m_Root, 
  581.                                   compilers);
  582.     m_ProjectTreeInfo->m_Compilers = 
  583.         CDirEntry::AddTrailingPathSeparator
  584.                    (m_ProjectTreeInfo->m_Compilers);
  585.     /// ImplicitExcludedBranches - all subdirs will be excluded by default
  586.     string implicit_exclude_str 
  587.         = GetConfig().GetString("ProjectTree", "ImplicitExclude", "");
  588.     list<string> implicit_exclude_list;
  589.     NStr::Split(implicit_exclude_str, 
  590.                 LIST_SEPARATOR, 
  591.                 implicit_exclude_list);
  592.     ITERATE(list<string>, p, implicit_exclude_list) {
  593.         const string& subdir = *p;
  594.         string dir = CDirEntry::ConcatPath(m_ProjectTreeInfo->m_Src, 
  595.                                            subdir);
  596.         dir = CDirEntry::AddTrailingPathSeparator(dir);
  597.         m_ProjectTreeInfo->m_ImplicitExcludedAbsDirs.push_back(dir);
  598.     }
  599.     /// <projects> branch of tree (scriptsprojects)
  600.     string projects = 
  601.         GetConfig().GetString("ProjectTree", "projects", "");
  602.     m_ProjectTreeInfo->m_Projects = 
  603.             CDirEntry::ConcatPath(m_ProjectTreeInfo->m_Root, 
  604.                                   projects);
  605.     m_ProjectTreeInfo->m_Projects = 
  606.         CDirEntry::AddTrailingPathSeparator
  607.                    (m_ProjectTreeInfo->m_Compilers);
  608.     /// impl part if include project node
  609.     m_ProjectTreeInfo->m_Impl = 
  610.         GetConfig().GetString("ProjectTree", "impl", "");
  611.     /// Makefile in tree node
  612.     m_ProjectTreeInfo->m_TreeNode = 
  613.         GetConfig().GetString("ProjectTree", "TreeNode", "");
  614.     return *m_ProjectTreeInfo;
  615. }
  616. const CBuildType& CProjBulderApp::GetBuildType(void)
  617. {
  618.     if ( !m_BuildType.get() ) {
  619.         CArgs args = GetArgs();
  620.         bool dll_build = args["dll"];
  621.         m_BuildType.reset(new CBuildType(dll_build));
  622.     }    
  623.     return *m_BuildType;
  624. }
  625. const CMsvcDllsInfo& CProjBulderApp::GetDllsInfo(void)
  626. {
  627.     if ( !m_DllsInfo.get() ) {
  628.         string site_ini_dir = GetProjectTreeInfo().m_Compilers;
  629.         site_ini_dir = 
  630.                 CDirEntry::ConcatPath(site_ini_dir, 
  631.                                       GetRegSettings().m_CompilersSubdir);
  632.         site_ini_dir = 
  633.             CDirEntry::ConcatPath(site_ini_dir, 
  634.                                   GetBuildType().GetTypeStr());
  635.         string dll_info_file_name = GetRegSettings().m_DllInfo;
  636.         dll_info_file_name =
  637.             CDirEntry::ConcatPath(site_ini_dir, dll_info_file_name);
  638.         m_DllsInfo.reset(new CMsvcDllsInfo(dll_info_file_name));
  639.     }    
  640.     return *m_DllsInfo;
  641. }
  642. const CProjectItemsTree& CProjBulderApp::GetWholeTree(void)
  643. {
  644.     if ( !m_WholeTree.get() ) {
  645.         m_WholeTree.reset(new CProjectItemsTree);
  646.         CProjectDummyFilter pass_all_filter;
  647.         CProjectTreeBuilder::BuildProjectTree(&pass_all_filter, 
  648.                                               GetProjectTreeInfo().m_Src, 
  649.                                               m_WholeTree.get());
  650.     }    
  651.     return *m_WholeTree;
  652. }
  653. CDllSrcFilesDistr& CProjBulderApp::GetDllFilesDistr(void)
  654. {
  655.     if (m_DllSrcFilesDistr.get())
  656.         return *m_DllSrcFilesDistr;
  657.     m_DllSrcFilesDistr.reset ( new CDllSrcFilesDistr() );
  658.     return *m_DllSrcFilesDistr;
  659. }
  660. string CProjBulderApp::GetDatatoolId(void) const
  661. {
  662.     return GetConfig().GetString("Datatool", "datatool", "datatool");
  663. }
  664. string CProjBulderApp::GetDatatoolPathForApp(void) const
  665. {
  666.     return GetConfig().GetString("Datatool", "Location.App", "datatool.exe");
  667. }
  668. string CProjBulderApp::GetDatatoolPathForLib(void) const
  669. {
  670.     return GetConfig().GetString("Datatool", "Location.Lib", "datatool.exe");
  671. }
  672. string CProjBulderApp::GetDatatoolCommandLine(void) const
  673. {
  674.     return GetConfig().GetString("Datatool", "CommandLine", "");
  675. }
  676. CProjBulderApp& GetApp(void)
  677. {
  678.     static CProjBulderApp theApp;
  679.     return theApp;
  680. }
  681. END_NCBI_SCOPE
  682. USING_NCBI_SCOPE;
  683. int main(int argc, const char* argv[])
  684. {
  685.     // Execute main application function
  686.     return GetApp().AppMain(argc, argv, 0, eDS_Default);
  687. }
  688. /*
  689.  * ===========================================================================
  690.  * $Log: proj_builder_app.cpp,v $
  691.  * Revision 1000.4  2004/06/16 17:02:36  gouriano
  692.  * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.43
  693.  *
  694.  * Revision 1.43  2004/06/15 19:01:40  gorelenk
  695.  * Fixed compilation errors on GCC 2.95 .
  696.  *
  697.  * Revision 1.42  2004/06/14 14:16:58  gorelenk
  698.  * Changed implementation of CProjBulderApp::GetProjectTreeInfo - added
  699.  * m_TreeNode .
  700.  *
  701.  * Revision 1.41  2004/06/07 19:14:54  gorelenk
  702.  * Changed CProjBulderApp::GetProjectTreeInfo .
  703.  *
  704.  * Revision 1.40  2004/06/07 13:57:43  gorelenk
  705.  * Changed implementation of CProjBulderApp::GetRegSettings and
  706.  * CProjBulderApp::GetDllsInfo.
  707.  *
  708.  * Revision 1.39  2004/05/21 21:41:41  gorelenk
  709.  * Added PCH ncbi_pch.hpp
  710.  *
  711.  * Revision 1.38  2004/05/19 14:23:40  gorelenk
  712.  * Implemented CProjBulderApp::GetDllFilesDistr .
  713.  *
  714.  * Revision 1.37  2004/05/17 16:21:38  gorelenk
  715.  * Implemeted CProjBulderApp::GetDllFilesDistr .
  716.  *
  717.  * Revision 1.36  2004/04/13 17:09:39  gorelenk
  718.  * Changed implementation of CProjBulderApp::Run .
  719.  *
  720.  * Revision 1.35  2004/04/08 18:45:56  gorelenk
  721.  * Conditionaly enabled exclude projects by msvc makefiles .
  722.  *
  723.  * Revision 1.34  2004/03/23 14:35:51  gorelenk
  724.  * Added implementation of CProjBulderApp::GetWholeTree.
  725.  *
  726.  * Revision 1.33  2004/03/10 21:29:27  gorelenk
  727.  * Changed implementation of CProjBulderApp::Run.
  728.  *
  729.  * Revision 1.32  2004/03/10 16:50:13  gorelenk
  730.  * Separated static build and dll build processing inside CProjBulderApp::Run.
  731.  *
  732.  * Revision 1.31  2004/03/08 23:37:01  gorelenk
  733.  * Implemented CProjBulderApp::GetDllsInfo.
  734.  *
  735.  * Revision 1.30  2004/03/05 18:08:26  gorelenk
  736.  * Excluded filtering of projects by .msvc makefiles.
  737.  *
  738.  * Revision 1.29  2004/03/03 22:20:02  gorelenk
  739.  * Added predicate PIsExcludedMakefileIn, class template CCombine,  redesigned
  740.  * projects exclusion inside CProjBulderApp::Run - to support local
  741.  * Makefile.in.msvc .
  742.  *
  743.  * Revision 1.28  2004/03/03 00:06:25  gorelenk
  744.  * Changed implementation of CProjBulderApp::Run.
  745.  *
  746.  * Revision 1.27  2004/03/02 23:35:41  gorelenk
  747.  * Changed implementation of CProjBulderApp::Init (added flag "dll").
  748.  * Added implementation of CProjBulderApp::GetBuildType.
  749.  *
  750.  * Revision 1.26  2004/03/02 16:25:41  gorelenk
  751.  * Added include for proj_tree_builder.hpp.
  752.  *
  753.  * Revision 1.25  2004/03/01 18:01:19  gorelenk
  754.  * Added processing times reporting to log. Added project tree checking
  755.  * for projects inter-dependencies.
  756.  *
  757.  * Revision 1.24  2004/02/26 21:31:51  gorelenk
  758.  * Re-designed CProjBulderApp::GetProjectTreeInfo - use creation of
  759.  * IProjectFilter-derived classes instead of string.
  760.  * Changed signature of call BuildProjectTree inside CProjBulderApp::Run.
  761.  *
  762.  * Revision 1.23  2004/02/25 19:44:04  gorelenk
  763.  * Added creation of BuildAll utility project to CProjBulderApp::Run.
  764.  *
  765.  * Revision 1.22  2004/02/20 22:53:58  gorelenk
  766.  * Added analysis of ASN projects depends.
  767.  *
  768.  * Revision 1.21  2004/02/18 23:37:06  gorelenk
  769.  * Changed definition of member-function GetProjectTreeInfo.
  770.  *
  771.  * Revision 1.20  2004/02/13 20:39:52  gorelenk
  772.  * Minor cosmetic changes.
  773.  *
  774.  * Revision 1.19  2004/02/13 17:52:42  gorelenk
  775.  * Added command line parametrs path normalization.
  776.  *
  777.  * Revision 1.18  2004/02/12 23:15:29  gorelenk
  778.  * Implemented utility projects creation and configure re-build of the app.
  779.  *
  780.  * Revision 1.17  2004/02/12 18:46:20  ivanov
  781.  * Removed extra argument from AppMain() call to autoload .ini file
  782.  *
  783.  * Revision 1.16  2004/02/12 17:41:52  gorelenk
  784.  * Implemented creation of MasterProject and ConfigureProject in different
  785.  * folder.
  786.  *
  787.  * Revision 1.15  2004/02/12 16:27:10  gorelenk
  788.  * Added _CONFIGURE_ project generation.
  789.  *
  790.  * Revision 1.14  2004/02/11 15:40:44  gorelenk
  791.  * Implemented support for multiple implicit excludes from source tree.
  792.  *
  793.  * Revision 1.13  2004/02/10 18:18:43  gorelenk
  794.  * Changed LOG_POST massages.
  795.  *
  796.  * Revision 1.12  2004/02/06 23:14:59  gorelenk
  797.  * Implemented support of ASN projects, semi-auto configure,
  798.  * CPPFLAGS support. Second working version.
  799.  *
  800.  * Revision 1.11  2004/02/04 23:59:52  gorelenk
  801.  * Changed log messages generation.
  802.  *
  803.  * Revision 1.10  2004/02/03 17:14:24  gorelenk
  804.  * Changed implementation of class CProjBulderApp member functions.
  805.  *
  806.  * Revision 1.9  2004/01/30 20:44:22  gorelenk
  807.  * Initial revision.
  808.  *
  809.  * Revision 1.8  2004/01/29 15:45:13  gorelenk
  810.  * Added support of project tree filtering
  811.  *
  812.  * Revision 1.7  2004/01/28 17:55:50  gorelenk
  813.  * += For msvc makefile support of :
  814.  *                 Requires tag, ExcludeProject tag,
  815.  *                 AddToProject section (SourceFiles and IncludeDirs),
  816.  *                 CustomBuild section.
  817.  * += For support of user local site.
  818.  *
  819.  * Revision 1.6  2004/01/26 19:27:30  gorelenk
  820.  * += MSVC meta makefile support
  821.  * += MSVC project makefile support
  822.  *
  823.  * Revision 1.5  2004/01/22 17:57:55  gorelenk
  824.  * first version
  825.  *
  826.  * ===========================================================================
  827.  */