📄 proj_tree_builder.cpp
字号:
const string& proj_name, const string& applib_mfilepath, const TFiles& makeapp, const TFiles& makelib, CProjectItemsTree* tree){ CProjItem::TProjType proj_type = SMakeProjectT::GetProjType(source_base_dir, proj_name); CProjKey proj_id = proj_type == CProjKey::eLib? SLibProjectT::DoCreate(source_base_dir, proj_name, applib_mfilepath, makelib, tree) : SAppProjectT::DoCreate(source_base_dir, proj_name, applib_mfilepath, makeapp, tree); if ( proj_id.Id().empty() ) return CProjKey(); TProjects::iterator p = tree->m_Projects.find(proj_id); if (p == tree->m_Projects.end()) { LOG_POST(Error << "Can not find ASN project with id : " + proj_id.Id()); return CProjKey(); } CProjItem& project = p->second; //Add depends from datatoool for ASN projects project.m_Depends.push_back(CProjKey(CProjKey::eApp, GetApp().GetDatatoolId())); //Will process .asn or .dtd files string source_file_path = CDirEntry::ConcatPath(source_base_dir, proj_name); if ( CDirEntry(source_file_path + ".asn").Exists() ) source_file_path += ".asn"; else if ( CDirEntry(source_file_path + ".dtd").Exists() ) source_file_path += ".dtd"; CDataToolGeneratedSrc data_tool_src; CDataToolGeneratedSrc::LoadFrom(source_file_path, &data_tool_src); if ( !data_tool_src.IsEmpty() ) project.m_DatatoolSources.push_back(data_tool_src); return proj_id;}//-----------------------------------------------------------------------------CProjKey SAsnProjectMultipleT::DoCreate(const string& source_base_dir, const string& proj_name, const string& applib_mfilepath, const TFiles& makeapp, const TFiles& makelib, CProjectItemsTree* tree){ CProjItem::TProjType proj_type = SMakeProjectT::GetProjType(source_base_dir, proj_name); const TFiles& makefile = proj_type == CProjKey::eLib? makelib : makeapp; TFiles::const_iterator m = makefile.find(applib_mfilepath); if (m == makefile.end()) { LOG_POST(Info << "No Makefile.*.lib/app for Makefile.in :" + applib_mfilepath); return CProjKey(); } const CSimpleMakeFileContents& fc = m->second; // ASN CSimpleMakeFileContents::TContents::const_iterator k = fc.m_Contents.find("ASN"); if (k == fc.m_Contents.end()) { LOG_POST(Error << "No ASN key in multiple ASN project:" + applib_mfilepath); return CProjKey(); } const list<string> asn_names = k->second; string parent_dir_abs = ParentDir(source_base_dir); list<CDataToolGeneratedSrc> datatool_sources; ITERATE(list<string>, p, asn_names) { const string& asn = *p; // one level up string asn_dir_abs = CDirEntry::ConcatPath(parent_dir_abs, asn); asn_dir_abs = CDirEntry::NormalizePath(asn_dir_abs); asn_dir_abs = CDirEntry::AddTrailingPathSeparator(asn_dir_abs); string asn_path_abs = CDirEntry::ConcatPath(asn_dir_abs, asn); if ( CDirEntry(asn_path_abs + ".asn").Exists() ) asn_path_abs += ".asn"; else if ( CDirEntry(asn_dir_abs + ".dtd").Exists() ) asn_path_abs += ".dtd"; CDataToolGeneratedSrc data_tool_src; CDataToolGeneratedSrc::LoadFrom(asn_path_abs, &data_tool_src); if ( !data_tool_src.IsEmpty() ) datatool_sources.push_back(data_tool_src); } // SRC k = fc.m_Contents.find("SRC"); if (k == fc.m_Contents.end()) { LOG_POST(Error << "No SRC key in multiple ASN project:" + applib_mfilepath); return CProjKey(); } const list<string> src_list = k->second; list<string> sources; ITERATE(list<string>, p, src_list) { const string& src = *p; if ( !CSymResolver::IsDefine(src) ) sources.push_back(src); } CProjKey proj_id = proj_type == CProjKey::eLib? SLibProjectT::DoCreate(source_base_dir, proj_name, applib_mfilepath, makelib, tree) : SAppProjectT::DoCreate(source_base_dir, proj_name, applib_mfilepath, makeapp, tree); if ( proj_id.Id().empty() ) return CProjKey(); TProjects::iterator p = tree->m_Projects.find(proj_id); if (p == tree->m_Projects.end()) { LOG_POST(Error << "Can not find ASN project with id : " +proj_id.Id()); return CProjKey(); } CProjItem& project = p->second; // Adjust created proj item //SRC - project.m_Sources.clear(); ITERATE(list<string>, p, src_list) { const string& src = *p; if ( !CSymResolver::IsDefine(src) ) project.m_Sources.push_front(src); } project.m_Sources.push_back(proj_name + "__"); project.m_Sources.push_back(proj_name + "___"); ITERATE(list<string>, p, asn_names) { const string& asn = *p; if (asn == proj_name) continue; string src(1, CDirEntry::GetPathSeparator()); src += ".."; src += CDirEntry::GetPathSeparator(); src += asn; src += CDirEntry::GetPathSeparator(); src += asn; project.m_Sources.push_back(src + "__"); project.m_Sources.push_back(src + "___"); } project.m_DatatoolSources = datatool_sources; //Add depends from datatoool for ASN projects project.m_Depends.push_back(CProjKey(CProjKey::eApp, GetApp().GetDatatoolId())); return proj_id;}//-----------------------------------------------------------------------------CProjKey SMsvcProjectT::DoCreate(const string& source_base_dir, const string& proj_name, const string& applib_mfilepath, const TFiles& makemsvc, CProjectItemsTree* tree){ TFiles::const_iterator m = makemsvc.find(applib_mfilepath); if (m == makemsvc.end()) { LOG_POST(Info << "No User makefile.*.* for Makefile.in :" + applib_mfilepath); return CProjKey(); } // VCPROJ - will map to src CSimpleMakeFileContents::TContents::const_iterator k = m->second.m_Contents.find("VCPROJ"); if (k == m->second.m_Contents.end()) { LOG_POST(Warning << "No VCPROJ key in User Makefile.*.* :" + applib_mfilepath); return CProjKey(); } list<string> sources = k->second; // depends - list<CProjKey> depends_ids; k = m->second.m_Contents.find("LIB_DEP"); if (k != m->second.m_Contents.end()) { const list<string> deps = k->second; ITERATE(list<string>, p, deps) { depends_ids.push_back(CProjKey(CProjKey::eLib, *p)); } } k = m->second.m_Contents.find("APP_DEP"); if (k != m->second.m_Contents.end()) { const list<string> deps = k->second; ITERATE(list<string>, p, deps) { depends_ids.push_back(CProjKey(CProjKey::eApp, *p)); } } k = m->second.m_Contents.find("DLL_DEP"); if (k != m->second.m_Contents.end()) { const list<string> deps = k->second; ITERATE(list<string>, p, deps) { depends_ids.push_back(CProjKey(CProjKey::eDll, *p)); } } k = m->second.m_Contents.find("MSVC_DEP"); if (k != m->second.m_Contents.end()) { const list<string> deps = k->second; ITERATE(list<string>, p, deps) { depends_ids.push_back(CProjKey(CProjKey::eMsvc, *p)); } } //requires list<string> requires; k = m->second.m_Contents.find("REQUIRES"); if (k != m->second.m_Contents.end()) requires = k->second; //project id k = m->second.m_Contents.find("MSVC_PROJ"); if (k == m->second.m_Contents.end() || k->second.empty()) { LOG_POST(Error << "No LIB key or empty in Makefile.*.lib :" + applib_mfilepath); return CProjKey(); } string proj_id = k->second.front(); list<string> libs_3_party; list<string> include_dirs; list<string> defines; CProjKey proj_key(CProjKey::eMsvc, proj_id); tree->m_Projects[proj_key] = CProjItem(CProjKey::eMsvc, proj_name, proj_id, source_base_dir, sources, depends_ids, requires, libs_3_party, include_dirs, defines); return proj_key;}//-----------------------------------------------------------------------------void CProjectTreeBuilder::BuildOneProjectTree(const IProjectFilter* filter, const string& root_src_path, CProjectItemsTree* tree){ SMakeFiles subtree_makefiles; ProcessDir(root_src_path, true, filter, &subtree_makefiles); // Resolve macrodefines list<string> metadata_files; GetApp().GetMetaDataFiles(&metadata_files); CSymResolver resolver; ITERATE(list<string>, p, metadata_files) { resolver += CSymResolver(CDirEntry::ConcatPath(root_src_path, *p)); } ResolveDefs(resolver, subtree_makefiles); // Build projects tree CProjectItemsTree::CreateFrom(root_src_path, subtree_makefiles.m_In, subtree_makefiles.m_Lib, subtree_makefiles.m_App, subtree_makefiles.m_User, tree);}void CProjectTreeBuilder::BuildProjectTree(const IProjectFilter* filter, const string& root_src_path, CProjectItemsTree* tree){ // Bulid subtree CProjectItemsTree target_tree; BuildOneProjectTree(filter, root_src_path, &target_tree); // Analyze subtree depends list<CProjKey> external_depends; target_tree.GetExternalDepends(&external_depends); // We have to add more projects to the target tree if ( !external_depends.empty() && !filter->PassAll() ) { list<CProjKey> depends_to_resolve = external_depends; while ( !depends_to_resolve.empty() ) { bool modified = false; ITERATE(list<CProjKey>, p, depends_to_resolve) { // id of project we have to resolve const CProjKey& prj_id = *p; CProjectItemsTree::TProjects::const_iterator n = GetApp().GetWholeTree().m_Projects.find(prj_id); if (n != GetApp().GetWholeTree().m_Projects.end()) { //insert this project to target_tree target_tree.m_Projects[prj_id] = n->second; modified = true; } else { LOG_POST (Error << "No project with id :" + prj_id.Id()); } } if (!modified) { //we done - no more projects was added to target_tree AddDatatoolSourcesDepends(&target_tree); *tree = target_tree; return; } else { //continue resolving dependences target_tree.GetExternalDepends(&depends_to_resolve); } } } AddDatatoolSourcesDepends(&target_tree); *tree = target_tree;}void CProjectTreeBuilder::ProcessDir(const string& dir_name, bool is_root, const IProjectFilter* filter, SMakeFiles* makefiles){#if 1 // Do not collect makefile from root directory CDir dir(dir_name); CDir::TEntries contents = dir.GetEntries("*"); ITERATE(CDir::TEntries, i, contents) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -