CMakePM: Do not treat generated files as project files

This would trigger an infinite loop.

Fixes: QTCREATORBUG-26207
Fixes: QTCREATORBUG-26204
Fixes: QTCREATORBUG-25346
Fixes: QTCREATORBUG-25995
Fixes: QTCREATORBUG-25183
Fixes: QTCREATORBUG-25512
Change-Id: Iaf081a00dcf318a0ec2708e839e0ab6535e0ef4d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Cristian Adam
2021-09-01 19:49:08 +02:00
parent 1030715abc
commit 27f0dd134f
6 changed files with 41 additions and 26 deletions

View File

@@ -53,7 +53,7 @@ using namespace CMakeProjectManager::Internal::FileApiDetails;
class CMakeFileResult
{
public:
QSet<FilePath> cmakeFiles;
QSet<CMakeFileInfo> cmakeFiles;
std::vector<std::unique_ptr<ProjectExplorer::FileNode>> cmakeNodesSource;
std::vector<std::unique_ptr<ProjectExplorer::FileNode>> cmakeNodesBuild;
@@ -61,7 +61,7 @@ public:
std::vector<std::unique_ptr<ProjectExplorer::FileNode>> cmakeListNodes;
};
CMakeFileResult extractCMakeFilesData(const std::vector<FileApiDetails::CMakeFileInfo> &cmakefiles,
CMakeFileResult extractCMakeFilesData(const std::vector<CMakeFileInfo> &cmakefiles,
const FilePath &sourceDirectory,
const FilePath &buildDirectory)
{
@@ -72,9 +72,11 @@ CMakeFileResult extractCMakeFilesData(const std::vector<FileApiDetails::CMakeFil
for (const CMakeFileInfo &info : cmakefiles) {
const FilePath sfn = FilePath::fromString(
QDir::cleanPath(sourceDir.absoluteFilePath(info.path)));
QDir::cleanPath(sourceDir.absoluteFilePath(info.path.toString())));
const int oldCount = result.cmakeFiles.count();
result.cmakeFiles.insert(sfn);
CMakeFileInfo absolute(info);
absolute.path = sfn;
result.cmakeFiles.insert(absolute);
if (oldCount < result.cmakeFiles.count()) {
if (info.isCMake && !info.isCMakeListsDotTxt) {
// Skip files that cmake considers to be part of the installation -- but include
@@ -109,7 +111,7 @@ class PreprocessedData
public:
CMakeProjectManager::CMakeConfig cache;
QSet<FilePath> cmakeFiles;
QSet<CMakeFileInfo> cmakeFiles;
std::vector<std::unique_ptr<ProjectExplorer::FileNode>> cmakeNodesSource;
std::vector<std::unique_ptr<ProjectExplorer::FileNode>> cmakeNodesBuild;

View File

@@ -44,12 +44,26 @@ namespace Internal {
class FileApiData;
class CMakeFileInfo
{
public:
bool operator==(const CMakeFileInfo& other) const { return path == other.path; }
Utils::FilePath path;
bool isCMake = false;
bool isCMakeListsDotTxt = false;
bool isExternal = false;
bool isGenerated = false;
};
inline uint qHash(const CMakeFileInfo &info, uint seed = 0) { return info.path.hash(seed); }
class FileApiQtcData
{
public:
QString errorMessage;
CMakeConfig cache;
QSet<Utils::FilePath> cmakeFiles;
QSet<CMakeFileInfo> cmakeFiles;
QList<CMakeBuildTarget> buildTargets;
ProjectExplorer::RawProjectParts projectParts;
std::unique_ptr<CMakeProjectNode> rootProjectNode;

View File

@@ -249,10 +249,10 @@ static std::vector<CMakeFileInfo> readCMakeFilesFile(const FilePath &cmakeFilesF
for (const QJsonValue &v : inputs) {
CMakeFileInfo info;
const QJsonObject input = v.toObject();
info.path = input.value("path").toString();
info.path = FilePath::fromString(input.value("path").toString());
info.isCMake = input.value("isCMake").toBool();
const QString filename = FilePath::fromString(info.path).fileName();
const QString filename = info.path.fileName();
info.isCMakeListsDotTxt = (filename.compare("CMakeLists.txt",
HostOsInfo::fileNameCaseSensitivity())
== 0);

View File

@@ -71,16 +71,6 @@ public:
Utils::FilePath jsonFile(const QString &kind, const Utils::FilePath &replyDir) const;
};
class CMakeFileInfo
{
public:
QString path;
bool isCMake = false;
bool isCMakeListsDotTxt = false;
bool isExternal = false;
bool isGenerated = false;
};
class Directory
{
public:
@@ -243,7 +233,7 @@ class FileApiData
public:
FileApiDetails::ReplyFileContents replyFile;
CMakeConfig cache;
std::vector<FileApiDetails::CMakeFileInfo> cmakeFiles;
std::vector<CMakeFileInfo> cmakeFiles;
FileApiDetails::Configuration codemodel;
std::vector<FileApiDetails::TargetDetails> targetDetails;
};

View File

@@ -88,8 +88,12 @@ void FileApiReader::setParameters(const BuildDirParameters &p)
void FileApiReader::resetData()
{
m_cmakeFiles.clear();
if (!m_parameters.sourceDirectory.isEmpty())
m_cmakeFiles.insert(m_parameters.sourceDirectory.pathAppended("CMakeLists.txt"));
if (!m_parameters.sourceDirectory.isEmpty()) {
CMakeFileInfo cmakeListsTxt;
cmakeListsTxt.path = m_parameters.sourceDirectory.pathAppended("CMakeLists.txt");
cmakeListsTxt.isCMakeListsDotTxt = true;
m_cmakeFiles.insert(cmakeListsTxt);
}
m_cache.clear();
m_buildTargets.clear();
@@ -124,8 +128,9 @@ void FileApiReader::parse(bool forceCMakeRun,
const bool hasArguments = !args.isEmpty();
const bool replyFileMissing = !replyFile.exists();
const bool cmakeFilesChanged = m_parameters.cmakeTool() && m_parameters.cmakeTool()->isAutoRun()
&& anyOf(m_cmakeFiles, [&replyFile](const FilePath &f) {
return f.lastModified() > replyFile.lastModified();
&& anyOf(m_cmakeFiles, [&replyFile](const CMakeFileInfo &info) {
return !info.isGenerated
&& info.path.lastModified() > replyFile.lastModified();
});
const bool queryFileChanged = anyOf(FileApiParser::cmakeQueryFilePaths(m_parameters.buildDirectory),
[&replyFile](const FilePath &qf) {
@@ -175,7 +180,10 @@ bool FileApiReader::isParsing() const
QSet<FilePath> FileApiReader::projectFilesToWatch() const
{
return m_cmakeFiles;
return Utils::transform(
Utils::filtered(m_cmakeFiles,
[](const CMakeFileInfo &info) { return !info.isGenerated; }),
[](const CMakeFileInfo &info) { return info.path;});
}
QList<CMakeBuildTarget> FileApiReader::takeBuildTargets(QString &errorMessage){
@@ -249,7 +257,7 @@ void FileApiReader::endState(const FilePath &replyFilePath)
const FilePath sourceDirectory = m_parameters.sourceDirectory;
const FilePath buildDirectory = m_parameters.buildDirectory;
const FilePath topCmakeFile = m_cmakeFiles.size() == 1 ? *m_cmakeFiles.begin() : FilePath{};
const FilePath topCmakeFile = m_cmakeFiles.size() == 1 ? (*m_cmakeFiles.begin()).path : FilePath{};
const QString cmakeBuildType = m_parameters.cmakeBuildType == "Build" ? "" : m_parameters.cmakeBuildType;
QTC_CHECK(!replyFilePath.needsDevice());

View File

@@ -28,6 +28,7 @@
#include "cmakebuildtarget.h"
#include "cmakeprocess.h"
#include "cmakeprojectnodes.h"
#include "fileapidataextractor.h"
#include <projectexplorer/rawprojectpart.h>
#include <projectexplorer/treescanner.h>
@@ -100,7 +101,7 @@ private:
// cmake data:
CMakeConfig m_cache;
QSet<Utils::FilePath> m_cmakeFiles;
QSet<CMakeFileInfo> m_cmakeFiles;
QList<CMakeBuildTarget> m_buildTargets;
ProjectExplorer::RawProjectParts m_projectParts;
std::unique_ptr<CMakeProjectNode> m_rootProjectNode;