forked from qt-creator/qt-creator
CppTools: Allow to limit the files to process by file size
...with the environment variable QTC_CPP_FILE_SIZE_LIMIT_MB. Task-number: QTCREATORBUG-14390 Change-Id: Iaefaa1a3db023b58f9351b96e1b9e2139797e280 Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
#include "cppsourceprocessor.h"
|
||||
#include "cpptoolsconstants.h"
|
||||
#include "cpptoolsplugin.h"
|
||||
#include "cpptoolsreuse.h"
|
||||
#include "editordocumenthandle.h"
|
||||
|
||||
#include <coreplugin/documentmanager.h>
|
||||
@@ -585,15 +586,38 @@ QByteArray CppModelManager::codeModelConfiguration() const
|
||||
return QByteArray::fromRawData(pp_configuration, qstrlen(pp_configuration));
|
||||
}
|
||||
|
||||
static QSet<QString> tooBigFilesRemoved(const QSet<QString> &files, int fileSizeLimit)
|
||||
{
|
||||
if (fileSizeLimit == 0)
|
||||
return files;
|
||||
|
||||
QSet<QString> result;
|
||||
QFileInfo fileInfo;
|
||||
|
||||
QSetIterator<QString> i(files);
|
||||
while (i.hasNext()) {
|
||||
const QString filePath = i.next();
|
||||
fileInfo.setFile(filePath);
|
||||
if (skipFileDueToSizeLimit(fileInfo), fileSizeLimit)
|
||||
continue;
|
||||
|
||||
result << filePath;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QFuture<void> CppModelManager::updateSourceFiles(const QSet<QString> &sourceFiles,
|
||||
ProgressNotificationMode mode)
|
||||
{
|
||||
if (sourceFiles.isEmpty() || !d->m_indexerEnabled)
|
||||
return QFuture<void>();
|
||||
|
||||
const auto filteredFiles = tooBigFilesRemoved(sourceFiles, fileSizeLimit());
|
||||
|
||||
if (d->m_indexingSupporter)
|
||||
d->m_indexingSupporter->refreshSourceFiles(sourceFiles, mode);
|
||||
return d->m_internalIndexingSupport->refreshSourceFiles(sourceFiles, mode);
|
||||
d->m_indexingSupporter->refreshSourceFiles(filteredFiles, mode);
|
||||
return d->m_internalIndexingSupport->refreshSourceFiles(filteredFiles, mode);
|
||||
}
|
||||
|
||||
QList<ProjectInfo> CppModelManager::projectInfos() const
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include "cppsourceprocessor.h"
|
||||
|
||||
#include "cppmodelmanager.h"
|
||||
#include "cpptoolsreuse.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
@@ -454,6 +455,10 @@ void CppSourceProcessor::sourceNeeded(unsigned line, const QString &fileName, In
|
||||
return;
|
||||
}
|
||||
|
||||
const QFileInfo info(absoluteFileName);
|
||||
if (skipFileDueToSizeLimit(info))
|
||||
return; // TODO: Add diagnostic message
|
||||
|
||||
// Otherwise get file contents
|
||||
unsigned editorRevision = 0;
|
||||
QByteArray contents;
|
||||
@@ -473,7 +478,6 @@ void CppSourceProcessor::sourceNeeded(unsigned line, const QString &fileName, In
|
||||
Document::Include inc(include, include, 0, IncludeLocal);
|
||||
document->addIncludeFile(inc);
|
||||
}
|
||||
const QFileInfo info(absoluteFileName);
|
||||
if (info.exists())
|
||||
document->setLastModified(info.lastModified());
|
||||
|
||||
|
@@ -38,6 +38,7 @@
|
||||
#include <cplusplus/LookupContext.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QSet>
|
||||
#include <QStringRef>
|
||||
#include <QTextCursor>
|
||||
@@ -250,4 +251,33 @@ TextEditor::TextEditorWidget::Link linkToSymbol(Symbol *symbol)
|
||||
return Link(filename, line, column);
|
||||
}
|
||||
|
||||
int fileSizeLimit()
|
||||
{
|
||||
static const QByteArray fileSizeLimitAsByteArray = qgetenv("QTC_CPP_FILE_SIZE_LIMIT_MB");
|
||||
static int fileSizeLimitAsInt = -1;
|
||||
|
||||
if (fileSizeLimitAsInt == -1) {
|
||||
bool ok;
|
||||
const int limit = fileSizeLimitAsByteArray.toInt(&ok);
|
||||
fileSizeLimitAsInt = ok && limit >= 0 ? limit : 0;
|
||||
}
|
||||
|
||||
return fileSizeLimitAsInt;
|
||||
}
|
||||
|
||||
bool skipFileDueToSizeLimit(const QFileInfo &fileInfo, int limitInMB)
|
||||
{
|
||||
if (limitInMB == 0) // unlimited
|
||||
return false;
|
||||
|
||||
const int fileSizeInMB = fileInfo.size() * 1000 * 1000;
|
||||
if (fileSizeInMB > limitInMB) {
|
||||
qWarning() << "Files to process limited by QTC_CPP_FILE_SIZE_LIMIT_MB, skipping"
|
||||
<< fileInfo.absoluteFilePath();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // CppTools
|
||||
|
@@ -39,6 +39,7 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QChar;
|
||||
class QFileInfo;
|
||||
class QStringRef;
|
||||
class QTextCursor;
|
||||
QT_END_NAMESPACE
|
||||
@@ -74,6 +75,9 @@ const CPlusPlus::Macro CPPTOOLS_EXPORT *findCanonicalMacro(const QTextCursor &cu
|
||||
QString CPPTOOLS_EXPORT correspondingHeaderOrSource(const QString &fileName, bool *wasHeader = 0);
|
||||
void CPPTOOLS_EXPORT switchHeaderSource();
|
||||
|
||||
int fileSizeLimit();
|
||||
bool skipFileDueToSizeLimit(const QFileInfo &fileInfo, int limitInMB = fileSizeLimit());
|
||||
|
||||
} // CppTools
|
||||
|
||||
#endif // CPPTOOLSREUSE_H
|
||||
|
Reference in New Issue
Block a user