logic: Fixed relative paths not working Code::Blocks project files (issue #663)
* Index non-target files if no others available
This commit is contained in:
@@ -28,7 +28,7 @@ namespace Codeblocks
|
||||
return std::shared_ptr<Project>();
|
||||
}
|
||||
|
||||
std::shared_ptr<Project> project(new Project());
|
||||
std::shared_ptr<Project> 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<Project>();
|
||||
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<Project>();
|
||||
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<Project>();
|
||||
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<Project>();
|
||||
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<Project>();
|
||||
return project;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -128,13 +128,6 @@ namespace Codeblocks
|
||||
std::set<FilePath> Project::getAllSourceFilePathsCanonical(
|
||||
const std::vector<std::wstring>& sourceExtensions
|
||||
) const
|
||||
{
|
||||
return utility::convert<FilePath, FilePath>(getAllSourceFilePaths(sourceExtensions), [](const FilePath& path) { return path.getCanonical(); });
|
||||
}
|
||||
|
||||
std::set<FilePath> Project::getAllSourceFilePaths(
|
||||
const std::vector<std::wstring>& sourceExtensions
|
||||
) const
|
||||
{
|
||||
const std::set<std::wstring> lowerSourceExtensions = utility::toSet(utility::convert<std::wstring, std::wstring>(
|
||||
sourceExtensions,
|
||||
@@ -142,17 +135,31 @@ namespace Codeblocks
|
||||
));
|
||||
|
||||
std::set<FilePath> filePaths;
|
||||
std::set<FilePath> nonTargetFilePaths;
|
||||
for (std::shared_ptr<const Unit> 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<FilePath> indexedHeaderPaths = utility::toSet(sourceGroupSettings->getIndexedHeaderPathsExpandedAndAbsolute());
|
||||
const std::set<FilePath> indexedHeaderPaths =
|
||||
utility::toSet(sourceGroupSettings->getIndexedHeaderPathsExpandedAndAbsolute());
|
||||
|
||||
const std::set<FilePathFilter> excludeFilters = utility::toSet(sourceGroupSettings->getExcludeFiltersExpandedAndAbsolute());
|
||||
const std::set<FilePathFilter> excludeFilters =
|
||||
utility::toSet(sourceGroupSettings->getExcludeFiltersExpandedAndAbsolute());
|
||||
|
||||
const std::vector<FilePath> systemHeaderSearchPaths = utility::concat(
|
||||
sourceGroupSettings->getHeaderSearchPathsExpandedAndAbsolute(),
|
||||
@@ -239,6 +248,7 @@ namespace Codeblocks
|
||||
});
|
||||
|
||||
std::vector<std::shared_ptr<IndexerCommandCxx>> indexerCommands;
|
||||
std::vector<std::shared_ptr<IndexerCommandCxx>> nonTargetIndexerCommands;
|
||||
for (std::shared_ptr<Unit> 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<IndexerCommandCxx>(
|
||||
filePath,
|
||||
utility::concat(indexedHeaderPaths, { filePath }),
|
||||
excludeFilters,
|
||||
std::set<FilePathFilter>(),
|
||||
sourceGroupSettings->getCodeblocksProjectPathExpandedAndAbsolute().getParentDirectory(),
|
||||
utility::concat(
|
||||
optionsCache.getValue(L""),
|
||||
std::vector<std::wstring>({
|
||||
IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard),
|
||||
filePath.wstr()
|
||||
})
|
||||
)
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const std::wstring& targetName : unit->getTargetNames())
|
||||
{
|
||||
indexerCommands.push_back(std::make_shared<IndexerCommandCxx>(
|
||||
@@ -275,12 +304,25 @@ namespace Codeblocks
|
||||
sourceGroupSettings->getCodeblocksProjectPathExpandedAndAbsolute().getParentDirectory(),
|
||||
utility::concat(
|
||||
optionsCache.getValue(targetName),
|
||||
std::vector<std::wstring>({ IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard), filePath.wstr() })
|
||||
std::vector<std::wstring>({
|
||||
IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard),
|
||||
filePath.wstr()
|
||||
})
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if (!indexerCommands.size())
|
||||
{
|
||||
return nonTargetIndexerCommands;
|
||||
}
|
||||
|
||||
return indexerCommands;
|
||||
}
|
||||
|
||||
Project::Project(const FilePath& projectFilePath)
|
||||
: m_projectFilePath(projectFilePath)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "FilePath.h"
|
||||
|
||||
class ApplicationSettings;
|
||||
class FilePath;
|
||||
class IndexerCommandCxx;
|
||||
@@ -24,12 +26,7 @@ namespace Codeblocks
|
||||
static std::shared_ptr<Project> load(const FilePath& projectFilePath);
|
||||
static std::shared_ptr<Project> load(std::shared_ptr<TextAccess> xmlAccess);
|
||||
|
||||
std::set<FilePath> getAllSourceFilePathsCanonical(
|
||||
const std::vector<std::wstring>& sourceExtensions
|
||||
) const;
|
||||
std::set<FilePath> getAllSourceFilePaths(
|
||||
const std::vector<std::wstring>& sourceExtensions
|
||||
) const;
|
||||
std::set<FilePath> getAllSourceFilePathsCanonical(const std::vector<std::wstring>& sourceExtensions) const;
|
||||
std::set<FilePath> getAllCxxHeaderSearchPathsCanonical() const;
|
||||
|
||||
std::vector<std::shared_ptr<IndexerCommandCxx>> getIndexerCommands(
|
||||
@@ -37,10 +34,12 @@ namespace Codeblocks
|
||||
std::shared_ptr<const ApplicationSettings> 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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Unit> create(const TiXmlElement* element);
|
||||
|
||||
std::wstring getFilename() const;
|
||||
FilePath getCanonicalFilePath(const FilePath& projectFileDirectory) const;
|
||||
CompilerVarType getCompilerVar() const;
|
||||
bool getCompile() const;
|
||||
std::set<std::wstring> getTargetNames() const;
|
||||
|
||||
@@ -327,7 +327,7 @@ std::vector<FilePath> 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()));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -73,6 +73,10 @@
|
||||
<Unit filename="<source_path>/main.cpp">
|
||||
<Option target="Test"/>
|
||||
</Unit>
|
||||
<Unit filename="src/test.cpp">
|
||||
<Option target="Test"/>
|
||||
</Unit>
|
||||
<Unit filename="src/no_target.cpp" />
|
||||
<Unit filename="<source_path>/CMakeLists.txt">
|
||||
<Option virtualFolder="CMake Files\"/>
|
||||
</Unit>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
void no_target()
|
||||
{
|
||||
int b = 7;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
void test()
|
||||
{
|
||||
int a = 42;
|
||||
}
|
||||
Reference in New Issue
Block a user