forked from qt-creator/qt-creator
CMake: Fix up file group information in server-mode
Server-mode reports a filegroup for all the listed headers and will provide that without any information on the files (no language, include paths, etc.). Fix up file groups like these by using the best (with that being the settings that effect the most other files) possible information for these files. CMake has no idea what headers are, so it has no way to provide any better information, so Creator has to fix things up again:-/ Task-number: QTCREATORBUG-17971 Change-Id: Ib5ddab23cf725c7e03717b577cc9f9edc5bbfc61 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -470,6 +470,8 @@ ServerModeReader::Target *ServerModeReader::extractTargetData(const QVariantMap
|
|||||||
target->fileGroups.append(extractFileGroupData(fgData, srcDir, target));
|
target->fileGroups.append(extractFileGroupData(fgData, srcDir, target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fixTarget(target);
|
||||||
|
|
||||||
m_targets.append(target);
|
m_targets.append(target);
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
@@ -548,6 +550,49 @@ void ServerModeReader::extractCacheData(const QVariantMap &data)
|
|||||||
m_cmakeCache = config;
|
m_cmakeCache = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerModeReader::fixTarget(ServerModeReader::Target *target) const
|
||||||
|
{
|
||||||
|
QHash<QString, const FileGroup *> languageFallbacks;
|
||||||
|
|
||||||
|
for (const FileGroup *group : Utils::asConst(target->fileGroups)) {
|
||||||
|
if (group->includePaths.isEmpty() && group->compileFlags.isEmpty()
|
||||||
|
&& group->defines.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const FileGroup *fallback = languageFallbacks.value(group->language);
|
||||||
|
if (!fallback || fallback->sources.count() < group->sources.count())
|
||||||
|
languageFallbacks.insert(group->language, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!languageFallbacks.value(""))
|
||||||
|
return; // No empty language groups found, no need to proceed.
|
||||||
|
|
||||||
|
const FileGroup *fallback = languageFallbacks.value("CXX");
|
||||||
|
if (!fallback)
|
||||||
|
fallback = languageFallbacks.value("C");
|
||||||
|
if (!fallback)
|
||||||
|
fallback = languageFallbacks.value("");
|
||||||
|
|
||||||
|
if (!fallback)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (auto it = target->fileGroups.begin(); it != target->fileGroups.end(); ++it) {
|
||||||
|
if (!(*it)->language.isEmpty())
|
||||||
|
continue;
|
||||||
|
(*it)->language = fallback->language.isEmpty() ? "CXX" : fallback->language;
|
||||||
|
|
||||||
|
if (*it == fallback
|
||||||
|
|| !(*it)->includePaths.isEmpty() || !(*it)->defines.isEmpty()
|
||||||
|
|| !(*it)->compileFlags.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (const IncludePath *ip : fallback->includePaths)
|
||||||
|
(*it)->includePaths.append(new IncludePath(*ip));
|
||||||
|
(*it)->defines = fallback->defines;
|
||||||
|
(*it)->compileFlags = fallback->compileFlags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QHash<Utils::FileName, ProjectNode *>
|
QHash<Utils::FileName, ProjectNode *>
|
||||||
ServerModeReader::addCMakeLists(CMakeProjectNode *root, const QList<FileNode *> &cmakeLists)
|
ServerModeReader::addCMakeLists(CMakeProjectNode *root, const QList<FileNode *> &cmakeLists)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ private:
|
|||||||
void extractCMakeInputsData(const QVariantMap &data);
|
void extractCMakeInputsData(const QVariantMap &data);
|
||||||
void extractCacheData(const QVariantMap &data);
|
void extractCacheData(const QVariantMap &data);
|
||||||
|
|
||||||
|
void fixTarget(Target *target) const;
|
||||||
|
|
||||||
QHash<Utils::FileName, ProjectExplorer::ProjectNode *>
|
QHash<Utils::FileName, ProjectExplorer::ProjectNode *>
|
||||||
addCMakeLists(CMakeProjectNode *root, const QList<ProjectExplorer::FileNode *> &cmakeLists);
|
addCMakeLists(CMakeProjectNode *root, const QList<ProjectExplorer::FileNode *> &cmakeLists);
|
||||||
void addProjects(const QHash<Utils::FileName, ProjectExplorer::ProjectNode *> &cmakeListsNodes,
|
void addProjects(const QHash<Utils::FileName, ProjectExplorer::ProjectNode *> &cmakeListsNodes,
|
||||||
|
|||||||
Reference in New Issue
Block a user