forked from qt-creator/qt-creator
AutoTest: Take precompiled headers into account
Test frameworks might be added to the precompiled headers. This in turn would make some pre-checks whether a file has to be processed or not fail. Fixes: QTCREATORBUG-25821 Change-Id: Iff69c1a83889cb6f79a3e3f9b2e59c5383989ccd Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -28,6 +28,10 @@
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <utils/textfileformat.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionMatch>
|
||||
|
||||
namespace Autotest {
|
||||
|
||||
@@ -69,6 +73,39 @@ QByteArray CppParser::getFileContent(const Utils::FilePath &filePath) const
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
bool precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
|
||||
const Utils::FilePath &filePath,
|
||||
const std::function<bool(const QString &)> &checker)
|
||||
{
|
||||
const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
||||
const QList<CppTools::ProjectPart::Ptr> projectParts = modelManager->projectPart(filePath);
|
||||
if (projectParts.isEmpty())
|
||||
return false;
|
||||
const QStringList precompiledHeaders = projectParts.first()->precompiledHeaders;
|
||||
auto headerContains = [&](const QString &header){
|
||||
return Utils::anyOf(snapshot.allIncludesForDocument(header), checker);
|
||||
};
|
||||
return Utils::anyOf(precompiledHeaders, headerContains);
|
||||
}
|
||||
|
||||
bool CppParser::precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
|
||||
const Utils::FilePath &filePath,
|
||||
const QString &headerFilePath)
|
||||
{
|
||||
return Autotest::precompiledHeaderContains(snapshot, filePath, [&](const QString &include) {
|
||||
return include.endsWith(headerFilePath);
|
||||
});
|
||||
}
|
||||
|
||||
bool CppParser::precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
|
||||
const Utils::FilePath &filePath,
|
||||
const QRegularExpression &headerFileRegex)
|
||||
{
|
||||
return Autotest::precompiledHeaderContains(snapshot, filePath, [&](const QString &include) {
|
||||
return headerFileRegex.match(include).hasMatch();
|
||||
});
|
||||
}
|
||||
|
||||
void CppParser::release()
|
||||
{
|
||||
m_cppSnapshot = CPlusPlus::Snapshot();
|
||||
|
||||
Reference in New Issue
Block a user