From cbcf605eb0735fcfc4094061a5fdb976d567659f Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Fri, 12 Jul 2024 11:16:35 +0200 Subject: [PATCH 1/2] Remove obsolete/unused vcimporter --- LiteEditor/manager.cpp | 1 - Plugin/vcimporter.cpp | 381 ----------------------------------------- Plugin/vcimporter.h | 72 -------- 3 files changed, 454 deletions(-) delete mode 100644 Plugin/vcimporter.cpp delete mode 100644 Plugin/vcimporter.h diff --git a/LiteEditor/manager.cpp b/LiteEditor/manager.cpp index 2132b32471..9170092303 100644 --- a/LiteEditor/manager.cpp +++ b/LiteEditor/manager.cpp @@ -725,7 +725,6 @@ void Manager::ImportMSVSSolution(const wxString& path, const wxString& defaultCo wxBusyInfo info(_("Importing IDE solution/workspace..."), clMainFrame::Get()); wxString errMsg; - // VcImporter importer(path, defaultCompiler); WSImporter importer; importer.Load(path, defaultCompiler); if (importer.Import(errMsg)) { diff --git a/Plugin/vcimporter.cpp b/Plugin/vcimporter.cpp deleted file mode 100644 index 00c70f34dc..0000000000 --- a/Plugin/vcimporter.cpp +++ /dev/null @@ -1,381 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// -// copyright : (C) 2008 by Eran Ifrah -// file name : vcimporter.cpp -// -// ------------------------------------------------------------------------- -// A -// _____ _ _ _ _ -// / __ \ | | | | (_) | -// | / \/ ___ __| | ___| | _| |_ ___ -// | | / _ \ / _ |/ _ \ | | | __/ _ ) -// | \__/\ (_) | (_| | __/ |___| | || __/ -// \____/\___/ \__,_|\___\_____/_|\__\___| -// -// F i l e -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -#include "vcimporter.h" - -#include "macros.h" -#include "workspace.h" -#include "wx/filename.h" -#include "wx/tokenzr.h" -#include "xmlutils.h" - -#define NEXT_LINE(line) \ - line.Empty(); \ - if(!ReadLine(line)) { \ - return false; \ - } - -VcImporter::VcImporter(const wxString& fileName, const wxString& defaultCompiler) - : m_fileName(fileName) - , m_is(NULL) - , m_tis(NULL) - , m_compiler(defaultCompiler) - , m_compilerLowercase(defaultCompiler) -{ - m_compilerLowercase.MakeLower(); - - wxFileName fn(m_fileName); - m_isOk = fn.FileExists(); - if(m_isOk) { - m_is = new wxFileInputStream(fn.GetFullPath()); - m_tis = new wxTextInputStream(*m_is); - } -} - -VcImporter::~VcImporter() -{ - if(m_is) { - delete m_is; - } - if(m_tis) { - delete m_tis; - } -} - -bool VcImporter::ReadLine(wxString& line) -{ - line = wxEmptyString; - if(m_isOk) { - while(!m_is->Eof()) { - line = m_tis->ReadLine(); - TrimString(line); - if(line.Length() == 1 || line.Length() == 2 || line.IsEmpty() || line.StartsWith(wxT("#"))) { - // get next line - continue; - } else { - return true; - } - } - } - return false; -} - -bool VcImporter::Import(wxString& errMsg) -{ - wxString line; - while(true) { - if(!ReadLine(line)) - break; - if(line.StartsWith(wxT("Project"))) { - if(!OnProject(line, errMsg)) { - return false; - } - } - } - - // create LE files - CreateWorkspace(); - CreateProjects(); - return true; -} - -bool VcImporter::OnProject(const wxString& firstLine, wxString& errMsg) -{ - // first line contains the project name, project file path, and project id - wxStringTokenizer tkz(firstLine, wxT("=")); - if(tkz.CountTokens() != 2) { - errMsg = wxT("Invalid 'Project' section found. expected = "); - return false; - } - - tkz.NextToken(); - wxString token = tkz.NextToken(); - TrimString(token); - wxStringTokenizer tk2(token, wxT(",")); - if(tk2.CountTokens() != 3) { - errMsg = wxT("Invalid 'Project' section found. expected , , "); - return false; - } - - VcProjectData pd; - - pd.name = tk2.NextToken(); - RemoveGershaim(pd.name); - - pd.filepath = tk2.NextToken(); - RemoveGershaim(pd.filepath); - - // Make sure that the project path has a forward slash style - pd.filepath.Replace(wxT("\\"), wxT("/")); - - pd.id = tk2.NextToken(); - RemoveGershaim(pd.id); - - std::pair p; - p.first = pd.id; - p.second = pd; - m_projects.insert(p); - // Skip all lines until EndProject section is found - wxString line; - while(true) { - NEXT_LINE(line); - if(line == wxT("EndProject")) { - return true; - } - } - return false; -} - -void VcImporter::RemoveGershaim(wxString& str) -{ - TrimString(str); - str = str.AfterFirst(wxT('"')); - str = str.BeforeLast(wxT('"')); -} - -void VcImporter::CreateWorkspace() -{ - // create a workspace file from the data we collected - wxFileName fn(m_fileName); - wxString errMsg; - clCxxWorkspaceST::Get()->CreateWorkspace(fn.GetName(), fn.GetPath(), errMsg); -} - -// -// ConfigurationType = 1 // exe -// ConfigurationType = 2 // dll -// ConfigurationType = 4 // static lib -// -void VcImporter::CreateProjects() -{ - std::map::iterator iter = m_projects.begin(); - for(; iter != m_projects.end(); iter++) { - // load xml file - VcProjectData pd = iter->second; - ConvertProject(pd); - } -} - -bool VcImporter::ConvertProject(VcProjectData& data) -{ - wxXmlDocument doc(data.filepath); - if(!doc.IsOk()) { - return false; - } - - // to create a project skeleton, we need the project type - // since VS allows each configuration to be of different - // type, while LE allows single type for all configurations - // we use the first configuration type that we find - wxXmlNode* configs = XmlUtils::FindFirstByTagName(doc.GetRoot(), wxT("Configurations")); - if(!configs) { - return false; - } - - // find the first configuration node - wxXmlNode* config = XmlUtils::FindFirstByTagName(configs, wxT("Configuration")); - if(!config) - return false; - // read the configuration type, default is set to Executeable - long type = XmlUtils::ReadLong(config, wxT("ConfigurationType"), 1); - wxString projectType; - wxString errMsg; - switch(type) { - case 2: // dll - projectType = PROJECT_TYPE_DYNAMIC_LIBRARY; - break; - case 4: // static library - projectType = PROJECT_TYPE_STATIC_LIBRARY; - break; - case 1: // exe - default: - projectType = PROJECT_TYPE_EXECUTABLE; - break; - } - // now we can create the project - wxFileName fn(data.filepath); - fn.MakeAbsolute(); - if(!clCxxWorkspaceST::Get()->CreateProject(data.name, fn.GetPath(), projectType, "", true, errMsg)) { - return false; - } - - // get the new project instance - ProjectPtr proj = clCxxWorkspaceST::Get()->FindProjectByName(data.name, errMsg); - ProjectSettingsPtr le_settings(new ProjectSettings(NULL)); - // remove the default 'Debug' configuration - le_settings->RemoveConfiguration(wxT("Debug")); - le_settings->SetProjectType(projectType); - - while(config) { - if(config->GetName() == wxT("Configuration")) { - AddConfiguration(le_settings, config); - } - config = config->GetNext(); - } - proj->SetSettings(le_settings); - // add all virtual folders - wxXmlNode* files = XmlUtils::FindFirstByTagName(doc.GetRoot(), wxT("Files")); - if(files) { - proj->BeginTranscation(); - CreateFiles(files, wxEmptyString, proj); - proj->CommitTranscation(); - } - return true; -} - -void VcImporter::AddConfiguration(ProjectSettingsPtr settings, wxXmlNode* config) -{ - // configuration name - wxString name = XmlUtils::ReadString(config, wxT("Name")); - name = name.BeforeFirst(wxT('|')); - name.Replace(wxT(" "), wxT("_")); - - BuildConfigPtr le_conf(new BuildConfig(NULL)); - le_conf->SetName(name); - le_conf->SetIntermediateDirectory(XmlUtils::ReadString(config, wxT("IntermediateDirectory"))); - // get the compiler settings - wxXmlNode* cmpNode = XmlUtils::FindNodeByName(config, wxT("Tool"), wxT("VCCLCompilerTool")); - // get the include directories - le_conf->SetIncludePath(SplitString(XmlUtils::ReadString(cmpNode, wxT("AdditionalIncludeDirectories")))); - le_conf->SetPreprocessor(XmlUtils::ReadString(cmpNode, wxT("PreprocessorDefinitions"))); - - // Select the best compiler for the import process (we select g++ by default) - le_conf->SetCompilerType(m_compiler); - - // Get the configuration type - long type = XmlUtils::ReadLong(config, wxT("ConfigurationType"), 1); - wxString projectType; - wxString errMsg; - switch(type) { - case 2: // dll - projectType = PROJECT_TYPE_DYNAMIC_LIBRARY; - break; - case 4: // static library - projectType = PROJECT_TYPE_STATIC_LIBRARY; - break; - case 1: // exe - default: - projectType = PROJECT_TYPE_EXECUTABLE; - break; - } - - le_conf->SetProjectType(projectType); - - // if project type is DLL or Executable, copy linker settings as well - if(settings->GetProjectType(le_conf->GetName()) == PROJECT_TYPE_EXECUTABLE || - settings->GetProjectType(le_conf->GetName()) == PROJECT_TYPE_DYNAMIC_LIBRARY) { - wxXmlNode* linkNode = XmlUtils::FindNodeByName(config, wxT("Tool"), wxT("VCLinkerTool")); - if(linkNode) { - wxString outputFileName(XmlUtils::ReadString(linkNode, wxT("OutputFile"))); -#ifndef __WXMSW__ - outputFileName.Replace(wxT(".dll"), wxT(".so")); - outputFileName.Replace(wxT(".exe"), wxT("")); -#endif - - le_conf->SetOutputFileName(outputFileName); - - // read in the additional libraries & libpath - wxString libs = XmlUtils::ReadString(linkNode, wxT("AdditionalDependencies")); - - // libs is a space delimited string - wxStringTokenizer tk(libs, wxT(" ")); - libs.Empty(); - while(tk.HasMoreTokens()) { - libs << tk.NextToken() << wxT(";"); - } - le_conf->SetLibraries(libs); - le_conf->SetLibPath(XmlUtils::ReadString(linkNode, wxT("AdditionalLibraryDirectories"))); - } - } else { - // static library - wxXmlNode* libNode = XmlUtils::FindNodeByName(config, wxT("Tool"), wxT("VCLibrarianTool")); - if(libNode) { - - wxString outputFileName(XmlUtils::ReadString(libNode, wxT("OutputFile"))); - outputFileName.Replace(wxT("\\"), wxT("/")); - - wxString outputFileNameOnly = outputFileName.AfterLast(wxT('/')); - wxString outputFilePath = outputFileName.BeforeLast(wxT('/')); - - if(m_compilerLowercase.Contains(wxT("gnu"))) { - if(outputFileNameOnly.StartsWith(wxT("lib")) == false) { - outputFileNameOnly.Prepend(wxT("lib")); - } - outputFileName.Clear(); - outputFileName << outputFilePath << wxT("/") << outputFileNameOnly; - outputFileName.Replace(wxT(".lib"), wxT(".a")); - } - le_conf->SetOutputFileName(outputFileName); - } - } - - // add the configuration - settings->SetBuildConfiguration(le_conf); -} - -void VcImporter::CreateFiles(wxXmlNode* parent, wxString vdPath, ProjectPtr proj) -{ - if(!parent) { - return; - } - - wxXmlNode* child = parent->GetChildren(); - while(child) { - if(child->GetName() == wxT("Filter")) { - // add new virtual directory - wxString name = XmlUtils::ReadString(child, wxT("Name")); - wxString tmpPath = vdPath; - if(tmpPath.IsEmpty() == false) { - tmpPath << wxT(":"); - } - tmpPath << name; - proj->CreateVirtualDir(tmpPath); - CreateFiles(child, tmpPath, proj); - - } else if(child->GetName() == wxT("File")) { - // found a file - wxString fileName = XmlUtils::ReadString(child, wxT("RelativePath")); - wxString path = vdPath; - if(path.IsEmpty()) { - path = wxT("src"); - } - - fileName.Replace(wxT("\\"), wxT("/")); - proj->AddFile(fileName, path); - } - child = child->GetNext(); - } -} - -wxArrayString VcImporter::SplitString(const wxString& s) -{ - wxArrayString arr; - wxString s1(s); - s1.Replace(wxT(","), wxT(";")); - wxStringTokenizer tk1(s1, wxT(";")); - while(tk1.HasMoreTokens()) { - arr.Add(tk1.NextToken()); - } - return arr; -} diff --git a/Plugin/vcimporter.h b/Plugin/vcimporter.h deleted file mode 100644 index def45a73a2..0000000000 --- a/Plugin/vcimporter.h +++ /dev/null @@ -1,72 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -// -// copyright : (C) 2008 by Eran Ifrah -// file name : vcimporter.h -// -// ------------------------------------------------------------------------- -// A -// _____ _ _ _ _ -// / __ \ | | | | (_) | -// | / \/ ___ __| | ___| | _| |_ ___ -// | | / _ \ / _ |/ _ \ | | | __/ _ ) -// | \__/\ (_) | (_| | __/ |___| | || __/ -// \____/\___/ \__,_|\___\_____/_|\__\___| -// -// F i l e -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -#ifndef VCIMPORTER_H -#define VCIMPORTER_H - -#include "codelite_exports.h" -#include "map" -#include "project.h" -#include "project_settings.h" -#include "wx/string.h" - -#include -#include - -struct VcProjectData { - wxString name; - wxString id; - wxString filepath; - wxArrayString deps; -}; - -class WXDLLIMPEXP_SDK VcImporter -{ - wxString m_fileName; - bool m_isOk; - wxFileInputStream* m_is; - wxTextInputStream* m_tis; - std::map m_projects; - wxString m_compiler; - wxString m_compilerLowercase; - -public: - VcImporter(const wxString& fileName, const wxString& defaultCompiler); - virtual ~VcImporter(); - bool Import(wxString& errMsg); - -private: - // read line, skip empty lines - bool ReadLine(wxString& line); - bool OnProject(const wxString& firstLine, wxString& errMsg); - void RemoveGershaim(wxString& str); - void CreateWorkspace(); - void CreateProjects(); - bool ConvertProject(VcProjectData& data); - void AddConfiguration(ProjectSettingsPtr settings, wxXmlNode* config); - void CreateFiles(wxXmlNode* parent, wxString vdPath, ProjectPtr proj); - wxArrayString SplitString(const wxString& s); -}; - -#endif // VCIMPORTER_H From 7fe2b13ba4d3e20d6cce8dceb8b4cfe8be770a8a Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Fri, 12 Jul 2024 17:24:20 +0200 Subject: [PATCH 2/2] Remove unused `clConcurrent` files --- CodeLite/clConcurrent.cpp | 47 --------------------------------------- CodeLite/clConcurrent.hpp | 31 -------------------------- 2 files changed, 78 deletions(-) delete mode 100644 CodeLite/clConcurrent.cpp delete mode 100644 CodeLite/clConcurrent.hpp diff --git a/CodeLite/clConcurrent.cpp b/CodeLite/clConcurrent.cpp deleted file mode 100644 index d136f2622e..0000000000 --- a/CodeLite/clConcurrent.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "clConcurrent.hpp" - -#include "file_logger.h" - -#include - -clConcurrent::clConcurrent(size_t pool_size) - : m_pool_size(pool_size) -{ - m_shutdown.store(false); -} - -clConcurrent::~clConcurrent() { shutdown(); } - -void clConcurrent::run() -{ - shutdown(); - m_thread_pool.reserve(m_pool_size); - - for(size_t i = 0; i < m_pool_size; ++i) { - std::thread* thr = new std::thread([&]() { - std::stringstream ss; - ss << std::this_thread::get_id(); - clDEBUG() << "worker thread #" << ss.str() << endl; - Callback command; - while(!m_shutdown.load()) { - Callback cb; - if(m_queue.ReceiveTimeout(100, cb) == wxMSGQUEUE_NO_ERROR) { - cb(); - } - } - clDEBUG() << "worker thread #" << ss.str() << "is going down" << endl; - }); - m_thread_pool.push_back(thr); - } -} - -void clConcurrent::shutdown() -{ - m_shutdown.store(true); - for(auto thr : m_thread_pool) { - thr->join(); - wxDELETE(thr); - } - m_thread_pool.clear(); - m_shutdown.store(false); -} diff --git a/CodeLite/clConcurrent.hpp b/CodeLite/clConcurrent.hpp deleted file mode 100644 index a9199bb56f..0000000000 --- a/CodeLite/clConcurrent.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef CLCONCURRENT_HPP -#define CLCONCURRENT_HPP - -#include "codelite_exports.h" - -#include -#include -#include -#include -#include - -class WXDLLIMPEXP_CL clConcurrent -{ - typedef std::function Callback; - std::vector m_thread_pool; - size_t m_pool_size = 1; - wxMessageQueue m_queue; - std::atomic_bool m_shutdown; - -public: - clConcurrent(size_t pool_size = 1); - virtual ~clConcurrent(); - - void run(); - void shutdown(); - void set_pool_size(size_t size) { m_pool_size = size; } - bool is_running() const { return !m_thread_pool.empty(); } - void queue(Callback callback) { m_queue.Post(callback); } -}; - -#endif // CLCONCURRENT_HPP