📄 msvc_prj_utils.cpp
字号:
/* * =========================================================================== * PRODUCTION $Log: msvc_prj_utils.cpp,v $ * PRODUCTION Revision 1000.3 2004/06/16 17:02:32 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.31 * PRODUCTION * =========================================================================== *//* $Id: msvc_prj_utils.cpp,v 1000.3 2004/06/16 17:02:32 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Author: Viatcheslav Gorelenkov * */#include <ncbi_pch.hpp>#include <app/project_tree_builder/msvc_prj_utils.hpp>#include <app/project_tree_builder/proj_builder_app.hpp>#include <app/project_tree_builder/msvc_prj_defines.hpp>#include <serial/objostrxml.hpp>#include <serial/objistr.hpp>#include <serial/serial.hpp>BEGIN_NCBI_SCOPECVisualStudioProject * LoadFromXmlFile(const string& file_path){ auto_ptr<CObjectIStream> in(CObjectIStream::Open(eSerial_Xml, file_path, eSerial_StdWhenAny)); if ( in->fail() ) NCBI_THROW(CProjBulderAppException, eFileOpen, file_path); auto_ptr<CVisualStudioProject> prj(new CVisualStudioProject()); in->Read(prj.get(), prj->GetThisTypeInfo()); return prj.release();}void SaveToXmlFile (const string& file_path, const CVisualStudioProject& project){ // Create dir if no such dir... string dir; CDirEntry::SplitPath(file_path, &dir); CDir project_dir(dir); if ( !project_dir.Exists() ) { CDir(dir).CreatePath(); } CNcbiOfstream ofs(file_path.c_str(), IOS_BASE::out | IOS_BASE::trunc ); if ( !ofs ) NCBI_THROW(CProjBulderAppException, eFileCreation, file_path); CObjectOStreamXml xs(ofs, false); xs.SetReferenceDTD(false); xs.SetEncoding(CObjectOStreamXml::eEncoding_Windows_1252); xs << project;}void PromoteIfDifferent(const string& present_path, const string& candidate_path){ // Open both files CNcbiIfstream ifs_present(present_path.c_str(), IOS_BASE::in | IOS_BASE::binary); if ( !ifs_present ) { NCBI_THROW(CProjBulderAppException, eFileOpen, present_path); } ifs_present.seekg(0, ios::end); size_t file_length_present = ifs_present.tellg() - streampos(0); ifs_present.seekg(0, ios::beg); CNcbiIfstream ifs_new (candidate_path.c_str(), IOS_BASE::in | IOS_BASE::binary); if ( !ifs_new ) { NCBI_THROW(CProjBulderAppException, eFileOpen, candidate_path); } ifs_new.seekg(0, ios::end); size_t file_length_new = ifs_new.tellg() - streampos(0); ifs_new.seekg(0, ios::beg); if (file_length_present != file_length_new) { ifs_present.close(); ifs_new.close(); CDirEntry(present_path).Remove(); CDirEntry(candidate_path).Rename(present_path); return; } // Load both to memory typedef AutoPtr<char, ArrayDeleter<char> > TAutoArray; TAutoArray buf_present = TAutoArray(new char [file_length_present]); TAutoArray buf_new = TAutoArray(new char [file_length_new]); ifs_present.read(buf_present.get(), file_length_present); ifs_new.read (buf_new.get(), file_length_new); ifs_present.close(); ifs_new.close(); // If candidate file is not the same as present file it'll be a new file if (memcmp(buf_present.get(), buf_new.get(), file_length_present) != 0) { CDirEntry(present_path).Remove(); CDirEntry(candidate_path).Rename(present_path); return; } else { CDirEntry(candidate_path).Remove(); }}void SaveIfNewer (const string& file_path, const CVisualStudioProject& project){ // If no such file then simple write it if ( !CDirEntry(file_path).Exists() ) { SaveToXmlFile(file_path, project); return; } // Save new file to tmp path. string candidate_file_path = file_path + ".candidate"; SaveToXmlFile(candidate_file_path, project); PromoteIfDifferent(file_path, candidate_file_path);}//-----------------------------------------------------------------------------class CGuidGenerator{public: ~CGuidGenerator(void); friend string GenerateSlnGUID(void);private: CGuidGenerator(void); const string root_guid; // root GUID for MSVC solutions const string guid_base; string Generate12Chars(void); unsigned int m_Seed; string DoGenerateSlnGUID(void); set<string> m_Trace;};string GenerateSlnGUID(void){ static CGuidGenerator guid_gen; return guid_gen.DoGenerateSlnGUID();}CGuidGenerator::CGuidGenerator(void) :root_guid("8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942"), guid_base("8BC9CEB8-8B4A-11D0-8D11-"), m_Seed(0){}CGuidGenerator::~CGuidGenerator(void){}string CGuidGenerator::Generate12Chars(void){ CNcbiOstrstream ost; ost.unsetf(ios::showbase); ost.setf (ios::uppercase); ost << hex << setw(12) << setfill('A') << m_Seed++ << ends << flush; return ost.str();}string CGuidGenerator::DoGenerateSlnGUID(void){ for ( ;; ) { //GUID prototype string proto = guid_base + Generate12Chars(); if (proto != root_guid && m_Trace.find(proto) == m_Trace.end()) { m_Trace.insert(proto); return "{" + proto + "}"; } }} string SourceFileExt(const string& file_path){ string ext; CDirEntry::SplitPath(file_path, NULL, NULL, &ext); bool explicit_c = NStr::CompareNocase(ext, ".c" )== 0; if (explicit_c && CFile(file_path).Exists()) { return ".c"; } bool explicit_cpp = NStr::CompareNocase(ext, ".cpp")== 0; if (explicit_cpp && CFile(file_path).Exists()) { return ".cpp"; } string file_path_cpp = file_path + ".cpp"; if ( CFile(file_path_cpp).Exists() ) return ".cpp"; string file_path_c = file_path + ".c"; if ( CFile(file_path_c).Exists() ) return ".c"; return "";}//-----------------------------------------------------------------------------SConfigInfo::SConfigInfo(void) :m_Debug(false){}SConfigInfo::SConfigInfo(const string& name, bool debug, const string& runtime_library) :m_Name (name), m_Debug (debug), m_RuntimeLibrary(runtime_library){}void LoadConfigInfoByNames(const CNcbiRegistry& registry, const list<string>& config_names, list<SConfigInfo>* configs){ ITERATE(list<string>, p, config_names) { const string& config_name = *p; SConfigInfo config; config.m_Name = config_name; config.m_Debug = registry.GetString(config_name, "debug", "FALSE") != "FALSE"; config.m_RuntimeLibrary = registry.GetString(config_name, "runtimeLibraryOption", "0"); configs->push_back(config); }}//-----------------------------------------------------------------------------CMsvc7RegSettings::CMsvc7RegSettings(void){ //TODO}bool IsSubdir(const string& abs_parent_dir, const string& abs_dir){ return abs_dir.find(abs_parent_dir) == 0;}string GetOpt(const CNcbiRegistry& registry, const string& section, const string& opt, const string& config){ string section_spec = section + '.' + config; string val_spec = registry.GetString(section_spec, opt, ""); if ( !val_spec.empty() ) return val_spec; return registry.GetString(section, opt, "");}string GetOpt(const CNcbiRegistry& registry, const string& section, const string& opt, const SConfigInfo& config){ string section_spec(section); section_spec += config.m_Debug? ".debug": ".release"; string section_dr(section_spec); //section.debug or section.release section_spec += '.'; section_spec += config.m_Name; string val_spec = registry.GetString(section_spec, opt, ""); if ( !val_spec.empty() ) return val_spec; val_spec = registry.GetString(section_dr, opt, ""); if ( !val_spec.empty() ) return val_spec; return registry.GetString(section, opt, "");}string ConfigName(const string& config){ return config +'|'+ MSVC_PROJECT_PLATFORM;}//-----------------------------------------------------------------------------CSrcToFilterInserterWithPch::CSrcToFilterInserterWithPch (const string& project_id, const list<SConfigInfo>& configs, const string& project_dir) :m_ProjectId (project_id), m_Configs (configs), m_ProjectDir (project_dir){}CSrcToFilterInserterWithPch::~CSrcToFilterInserterWithPch(void){}void CSrcToFilterInserterWithPch::operator()(CRef<CFilter>& filter, const string& rel_source_file){ CRef< CFFile > file(new CFFile()); file->SetAttlist().SetRelativePath(rel_source_file); // TPch pch_usage = DefinePchUsage(m_ProjectDir, rel_source_file); // ITERATE(list<SConfigInfo>, n , m_Configs) { // Iterate all configurations const string& config = (*n).m_Name; CRef<CFileConfiguration> file_config(new CFileConfiguration()); file_config->SetAttlist().SetName(ConfigName(config)); CRef<CTool> compilerl_tool(new CTool("")); compilerl_tool->SetAttlist().SetName("VCCLCompilerTool"); if (pch_usage.first == eCreate) { compilerl_tool->SetAttlist().SetPreprocessorDefinitions (GetApp().GetMetaMakefile().GetPchUsageDefine()); compilerl_tool->SetAttlist().SetUsePrecompiledHeader("1");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -