diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksProject.cpp b/src/lib_cxx/utility/codeblocks/CodeblocksProject.cpp index a4306377..13fcf02d 100644 --- a/src/lib_cxx/utility/codeblocks/CodeblocksProject.cpp +++ b/src/lib_cxx/utility/codeblocks/CodeblocksProject.cpp @@ -28,7 +28,7 @@ namespace Codeblocks return std::shared_ptr(); } - std::shared_ptr project(new Project()); + std::shared_ptr project(new Project(xmlAccess->getFilePath())); TiXmlDocument doc; doc.Parse(xmlAccess->getText().c_str(), 0, TIXML_ENCODING_UTF8); @@ -38,7 +38,7 @@ namespace Codeblocks "Unable to parse Code::Blocks project because of an error in row " + std::to_string(doc.ErrorRow()) + ", col " + std::to_string(doc.ErrorCol()) + ": " + std::string(doc.ErrorDesc()) ); - return std::shared_ptr(); + return project; } TiXmlElement* codeBlocksProjectFileElement; @@ -52,7 +52,7 @@ namespace Codeblocks if (codeBlocksProjectFileElement == nullptr) { LOG_ERROR("Unable to find root node in Code::Blocks project."); - return std::shared_ptr(); + return project; } } @@ -62,13 +62,13 @@ namespace Codeblocks if (versionElement->QueryIntAttribute("major", &project->m_versionMajor) != TIXML_SUCCESS) { LOG_ERROR("Unable to find \"Project\" node in Code::Blocks project."); - return std::shared_ptr(); + return project; } if (versionElement->QueryIntAttribute("minor", &project->m_versionMinor) != TIXML_SUCCESS) { LOG_ERROR("Unable to find \"Project\" node in Code::Blocks project."); - return std::shared_ptr(); + return project; } } @@ -76,7 +76,7 @@ namespace Codeblocks if (codeBlocksProjectFileElement == nullptr) { LOG_ERROR("Unable to find \"Project\" node in Code::Blocks project."); - return std::shared_ptr(); + return project; } { @@ -128,13 +128,6 @@ namespace Codeblocks std::set Project::getAllSourceFilePathsCanonical( const std::vector& sourceExtensions ) const - { - return utility::convert(getAllSourceFilePaths(sourceExtensions), [](const FilePath& path) { return path.getCanonical(); }); - } - - std::set Project::getAllSourceFilePaths( - const std::vector& sourceExtensions - ) const { const std::set lowerSourceExtensions = utility::toSet(utility::convert( sourceExtensions, @@ -142,17 +135,31 @@ namespace Codeblocks )); std::set filePaths; + std::set nonTargetFilePaths; for (std::shared_ptr unit : m_units) { if (unit && unit->getCompile()) { - FilePath filePath(unit->getFilename()); + FilePath filePath(unit->getCanonicalFilePath(m_projectFilePath.getParentDirectory())); if (lowerSourceExtensions.find(filePath.getLowerCase().extension()) != lowerSourceExtensions.end()) { - filePaths.insert(filePath); + if (unit->getTargetNames().size()) + { + filePaths.insert(filePath); + } + else + { + nonTargetFilePaths.insert(filePath); + } } } } + + if (!filePaths.size()) + { + return nonTargetFilePaths; + } + return filePaths; } @@ -202,9 +209,11 @@ namespace Codeblocks [](const std::wstring& e) { return utility::toLowerCase(e); } )); - const std::set indexedHeaderPaths = utility::toSet(sourceGroupSettings->getIndexedHeaderPathsExpandedAndAbsolute()); + const std::set indexedHeaderPaths = + utility::toSet(sourceGroupSettings->getIndexedHeaderPathsExpandedAndAbsolute()); - const std::set excludeFilters = utility::toSet(sourceGroupSettings->getExcludeFiltersExpandedAndAbsolute()); + const std::set excludeFilters = + utility::toSet(sourceGroupSettings->getExcludeFiltersExpandedAndAbsolute()); const std::vector systemHeaderSearchPaths = utility::concat( sourceGroupSettings->getHeaderSearchPathsExpandedAndAbsolute(), @@ -239,6 +248,7 @@ namespace Codeblocks }); std::vector> indexerCommands; + std::vector> nonTargetIndexerCommands; for (std::shared_ptr unit : m_units) { if (!unit || !unit->getCompile()) @@ -246,7 +256,7 @@ namespace Codeblocks continue; } - const FilePath filePath = FilePath(unit->getFilename()).makeCanonical(); + const FilePath filePath = unit->getCanonicalFilePath(m_projectFilePath.getParentDirectory()); if (lowerSourceExtensions.find(filePath.getLowerCase().extension()) == lowerSourceExtensions.end()) { continue; @@ -265,6 +275,25 @@ namespace Codeblocks continue; } + if (!unit->getTargetNames().size()) + { + nonTargetIndexerCommands.push_back(std::make_shared( + filePath, + utility::concat(indexedHeaderPaths, { filePath }), + excludeFilters, + std::set(), + sourceGroupSettings->getCodeblocksProjectPathExpandedAndAbsolute().getParentDirectory(), + utility::concat( + optionsCache.getValue(L""), + std::vector({ + IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard), + filePath.wstr() + }) + ) + )); + continue; + } + for (const std::wstring& targetName : unit->getTargetNames()) { indexerCommands.push_back(std::make_shared( @@ -275,12 +304,25 @@ namespace Codeblocks sourceGroupSettings->getCodeblocksProjectPathExpandedAndAbsolute().getParentDirectory(), utility::concat( optionsCache.getValue(targetName), - std::vector({ IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard), filePath.wstr() }) + std::vector({ + IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard), + filePath.wstr() + }) ) )); } } + if (!indexerCommands.size()) + { + return nonTargetIndexerCommands; + } + return indexerCommands; } + + Project::Project(const FilePath& projectFilePath) + : m_projectFilePath(projectFilePath) + { + } } diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksProject.h b/src/lib_cxx/utility/codeblocks/CodeblocksProject.h index a2050b1c..ba50adb5 100644 --- a/src/lib_cxx/utility/codeblocks/CodeblocksProject.h +++ b/src/lib_cxx/utility/codeblocks/CodeblocksProject.h @@ -6,6 +6,8 @@ #include #include +#include "FilePath.h" + class ApplicationSettings; class FilePath; class IndexerCommandCxx; @@ -24,12 +26,7 @@ namespace Codeblocks static std::shared_ptr load(const FilePath& projectFilePath); static std::shared_ptr load(std::shared_ptr xmlAccess); - std::set getAllSourceFilePathsCanonical( - const std::vector& sourceExtensions - ) const; - std::set getAllSourceFilePaths( - const std::vector& sourceExtensions - ) const; + std::set getAllSourceFilePathsCanonical(const std::vector& sourceExtensions) const; std::set getAllCxxHeaderSearchPathsCanonical() const; std::vector> getIndexerCommands( @@ -37,10 +34,12 @@ namespace Codeblocks std::shared_ptr appSettings) const; private: - Project() = default; + Project(const FilePath& projectFilePath); - int m_versionMajor; - int m_versionMinor; + FilePath m_projectFilePath; + + int m_versionMajor = 0; + int m_versionMinor = 0; std::wstring m_title; diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksUnit.cpp b/src/lib_cxx/utility/codeblocks/CodeblocksUnit.cpp index 7629be22..5fd33358 100644 --- a/src/lib_cxx/utility/codeblocks/CodeblocksUnit.cpp +++ b/src/lib_cxx/utility/codeblocks/CodeblocksUnit.cpp @@ -2,6 +2,7 @@ #include "tinyxml.h" +#include "FilePath.h" #include "utilityString.h" namespace Codeblocks @@ -60,9 +61,16 @@ namespace Codeblocks return unit; } - std::wstring Unit::getFilename() const + FilePath Unit::getCanonicalFilePath(const FilePath& projectFileDirectory) const { - return m_filename; + FilePath path(m_filename); + + if (!path.exists() || !path.isAbsolute()) + { + path = projectFileDirectory.getConcatenated(path); + } + + return path.makeCanonical(); } CompilerVarType Unit::getCompilerVar() const diff --git a/src/lib_cxx/utility/codeblocks/CodeblocksUnit.h b/src/lib_cxx/utility/codeblocks/CodeblocksUnit.h index 69ac2892..28cde223 100644 --- a/src/lib_cxx/utility/codeblocks/CodeblocksUnit.h +++ b/src/lib_cxx/utility/codeblocks/CodeblocksUnit.h @@ -6,6 +6,7 @@ #include "CodeblocksCompilerVarType.h" +class FilePath; class TiXmlElement; namespace Codeblocks @@ -16,7 +17,7 @@ namespace Codeblocks static std::string getXmlElementName(); static std::shared_ptr create(const TiXmlElement* element); - std::wstring getFilename() const; + FilePath getCanonicalFilePath(const FilePath& projectFileDirectory) const; CompilerVarType getCompilerVar() const; bool getCompile() const; std::set getTargetNames() const; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index 41c295b7..fee47ec2 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -327,7 +327,7 @@ std::vector QtProjectWizzardContentIndexedHeaderPaths::getIndexedPaths return path.getCanonical(); }); - for (const FilePath& path : codeblocksProject->getAllSourceFilePaths(settings->getSourceExtensions())) + for (const FilePath& path : codeblocksProject->getAllSourceFilePathsCanonical(settings->getSourceExtensions())) { indexedHeaderPaths.insert(canonicalDirectoryPathCache.getValue(path.getParentDirectory())); } diff --git a/testing/project_setup/cxx_cbp/checklist.txt b/testing/project_setup/cxx_cbp/checklist.txt index 6273fa37..bbcc7e34 100644 --- a/testing/project_setup/cxx_cbp/checklist.txt +++ b/testing/project_setup/cxx_cbp/checklist.txt @@ -8,7 +8,7 @@ * Click "Next" * Pick "Test.cbp" at "Code::Blocks Project" * Click "show source files" button -* Validate "Source Files" list contains "src/main.cpp" +* Validate "Source Files" list contains 2 files: "src/main.cpp", "src/test.cpp" * Click "OK" * Validate "Header Files & Directories to Index" contains "src" entry * Add "**/Foo.h" to "Excluded Files & Directories" @@ -24,7 +24,7 @@ * Click "Cancel" * Run "2_update.sh" * Press "Refresh" button -* Validate "Files to clear" shows "3" +* Validate "Files to clear" shows "4" * Validate "source files to index" shows "1" * Click "Start" * Validate Project indexed without error diff --git a/testing/project_setup/cxx_cbp/data/Test.cbp b/testing/project_setup/cxx_cbp/data/Test.cbp index c2f4f98b..a7cd8507 100644 --- a/testing/project_setup/cxx_cbp/data/Test.cbp +++ b/testing/project_setup/cxx_cbp/data/Test.cbp @@ -73,6 +73,10 @@ + + + diff --git a/testing/project_setup/cxx_cbp/data/src/no_target.cpp b/testing/project_setup/cxx_cbp/data/src/no_target.cpp new file mode 100644 index 00000000..fa9ab62f --- /dev/null +++ b/testing/project_setup/cxx_cbp/data/src/no_target.cpp @@ -0,0 +1,4 @@ +void no_target() +{ + int b = 7; +} diff --git a/testing/project_setup/cxx_cbp/data/src/test.cpp b/testing/project_setup/cxx_cbp/data/src/test.cpp new file mode 100644 index 00000000..c89797ad --- /dev/null +++ b/testing/project_setup/cxx_cbp/data/src/test.cpp @@ -0,0 +1,4 @@ +void test() +{ + int a = 42; +}