forked from qt-creator/qt-creator
RunControl: Pass on toolchain defines and language options
Change-Id: I3a44707f7f27e1b4bb781886b63b23a3c20e0414 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -57,15 +57,15 @@ ClangStaticAnalyzerRunControl::ClangStaticAnalyzerRunControl(
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static QList<ClangStaticAnalyzerRunControl::FileConfiguration> calculateFilesToProcess(
|
static QList<ClangStaticAnalyzerRunControl::SourceFileConfiguration> calculateFilesToProcess(
|
||||||
Project *project)
|
Project *project)
|
||||||
{
|
{
|
||||||
typedef ClangStaticAnalyzerRunControl::FileConfiguration ProjectFileConfiguration;
|
typedef ClangStaticAnalyzerRunControl::SourceFileConfiguration SourceFileConfiguration;
|
||||||
QTC_ASSERT(project, return QList<ProjectFileConfiguration>());
|
QTC_ASSERT(project, return QList<SourceFileConfiguration>());
|
||||||
ProjectInfo projectInfo = CppModelManager::instance()->projectInfo(project);
|
ProjectInfo projectInfo = CppModelManager::instance()->projectInfo(project);
|
||||||
QTC_ASSERT(projectInfo, return QList<ProjectFileConfiguration>());
|
QTC_ASSERT(projectInfo, return QList<SourceFileConfiguration>());
|
||||||
|
|
||||||
QList<ProjectFileConfiguration> files;
|
QList<SourceFileConfiguration> files;
|
||||||
const QList<ProjectPart::Ptr> projectParts = projectInfo.projectParts();
|
const QList<ProjectPart::Ptr> projectParts = projectInfo.projectParts();
|
||||||
foreach (const ProjectPart::Ptr &projectPart, projectParts) {
|
foreach (const ProjectPart::Ptr &projectPart, projectParts) {
|
||||||
foreach (const ProjectFile &file, projectPart->files) {
|
foreach (const ProjectFile &file, projectPart->files) {
|
||||||
@@ -73,7 +73,7 @@ static QList<ClangStaticAnalyzerRunControl::FileConfiguration> calculateFilesToP
|
|||||||
continue;
|
continue;
|
||||||
QTC_CHECK(file.kind != ProjectFile::Unclassified);
|
QTC_CHECK(file.kind != ProjectFile::Unclassified);
|
||||||
if (ProjectFile::isSource(file.kind))
|
if (ProjectFile::isSource(file.kind))
|
||||||
files << ProjectFileConfiguration(file.path, projectPart);
|
files << SourceFileConfiguration(file, projectPart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,10 +111,10 @@ bool ClangStaticAnalyzerRunControl::startEngine()
|
|||||||
m_clangLogFileDir = temporaryDir.path();
|
m_clangLogFileDir = temporaryDir.path();
|
||||||
|
|
||||||
// Collect files
|
// Collect files
|
||||||
const QList<FileConfiguration> filesToProcess = calculateFilesToProcess(currentProject);
|
const QList<SourceFileConfiguration> filesToProcess = calculateFilesToProcess(currentProject);
|
||||||
qCDebug(LOG()) << "Files to process:";
|
qCDebug(LOG()) << "Files to process:";
|
||||||
foreach (const FileConfiguration &fileConfig, filesToProcess) {
|
foreach (const SourceFileConfiguration &fileConfig, filesToProcess) {
|
||||||
qCDebug(LOG()) << fileConfig.filePath + QLatin1String(" [")
|
qCDebug(LOG()) << fileConfig.file.path + QLatin1String(" [")
|
||||||
+ fileConfig.projectPart->projectFile + QLatin1Char(']');
|
+ fileConfig.projectPart->projectFile + QLatin1Char(']');
|
||||||
}
|
}
|
||||||
m_filesToProcess = filesToProcess;
|
m_filesToProcess = filesToProcess;
|
||||||
@@ -144,15 +144,6 @@ void ClangStaticAnalyzerRunControl::stopEngine()
|
|||||||
m_filesToProcess.clear();
|
m_filesToProcess.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList createDefinesAndIncludesOptions(const ProjectPart::Ptr projectPart)
|
|
||||||
{
|
|
||||||
QStringList result;
|
|
||||||
result += CppTools::CompilerOptionsBuilder::createDefineOptions(projectPart->projectDefines);
|
|
||||||
result += CppTools::CompilerOptionsBuilder::createHeaderPathOptions(projectPart->headerPaths);
|
|
||||||
result += QLatin1String("-fPIC"); // TODO: Remove?
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClangStaticAnalyzerRunControl::analyzeNextFile()
|
void ClangStaticAnalyzerRunControl::analyzeNextFile()
|
||||||
{
|
{
|
||||||
if (m_progress.isFinished())
|
if (m_progress.isFinished())
|
||||||
@@ -167,14 +158,13 @@ void ClangStaticAnalyzerRunControl::analyzeNextFile()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FileConfiguration config = m_filesToProcess.takeFirst();
|
const SourceFileConfiguration config = m_filesToProcess.takeFirst();
|
||||||
const QString filePath = config.filePath;
|
const QString filePath = config.file.path;
|
||||||
const QStringList definesAndIncludesOptions
|
const QStringList options = config.createClangOptions();
|
||||||
= createDefinesAndIncludesOptions(config.projectPart);
|
|
||||||
|
|
||||||
ClangStaticAnalyzerRunner *runner = createRunner();
|
ClangStaticAnalyzerRunner *runner = createRunner();
|
||||||
qCDebug(LOG) << "analyzeNextFile:" << filePath;
|
qCDebug(LOG) << "analyzeNextFile:" << filePath;
|
||||||
QTC_ASSERT(runner->run(filePath, definesAndIncludesOptions), return);
|
QTC_ASSERT(runner->run(filePath, options), return);
|
||||||
++m_runningProcesses;
|
++m_runningProcesses;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,5 +222,26 @@ void ClangStaticAnalyzerRunControl::updateProgressValue()
|
|||||||
m_progress.setProgressValue(m_initialFilesToProcessSize - m_filesToProcess.size());
|
m_progress.setProgressValue(m_initialFilesToProcessSize - m_filesToProcess.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList ClangStaticAnalyzerRunControl::SourceFileConfiguration::createClangOptions() const
|
||||||
|
{
|
||||||
|
QStringList result;
|
||||||
|
|
||||||
|
if (file.path.endsWith(QLatin1String("cppmodelmanager.cpp"))) {
|
||||||
|
qDebug() << "here";
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool objcExt = projectPart->languageExtensions & ProjectPart::ObjectiveCExtensions;
|
||||||
|
result += CppTools::CompilerOptionsBuilder::createLanguageOption(file.kind, objcExt);
|
||||||
|
result += CppTools::CompilerOptionsBuilder::createOptionsForLanguage(
|
||||||
|
projectPart->languageVersion,
|
||||||
|
projectPart->languageExtensions);
|
||||||
|
result += CppTools::CompilerOptionsBuilder::createDefineOptions(projectPart->toolchainDefines);
|
||||||
|
result += CppTools::CompilerOptionsBuilder::createDefineOptions(projectPart->projectDefines);
|
||||||
|
result += CppTools::CompilerOptionsBuilder::createHeaderPathOptions(projectPart->headerPaths);
|
||||||
|
result += QLatin1String("-fPIC"); // TODO: Remove?
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace ClangStaticAnalyzer
|
} // namespace ClangStaticAnalyzer
|
||||||
|
@@ -36,12 +36,15 @@ class ClangStaticAnalyzerRunControl : public Analyzer::AnalyzerRunControl
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct FileConfiguration {
|
struct SourceFileConfiguration {
|
||||||
FileConfiguration(const QString &filePath, const CppTools::ProjectPart::Ptr &projectPart)
|
SourceFileConfiguration(const CppTools::ProjectFile &projectFile,
|
||||||
: filePath(filePath)
|
const CppTools::ProjectPart::Ptr &projectPart)
|
||||||
|
: file(projectFile)
|
||||||
, projectPart(projectPart) {}
|
, projectPart(projectPart) {}
|
||||||
|
|
||||||
QString filePath;
|
QStringList createClangOptions() const;
|
||||||
|
|
||||||
|
CppTools::ProjectFile file;
|
||||||
CppTools::ProjectPart::Ptr projectPart;
|
CppTools::ProjectPart::Ptr projectPart;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,7 +73,7 @@ private:
|
|||||||
QString m_clangExecutable;
|
QString m_clangExecutable;
|
||||||
QString m_clangLogFileDir;
|
QString m_clangLogFileDir;
|
||||||
QFutureInterface<void> m_progress;
|
QFutureInterface<void> m_progress;
|
||||||
QList<FileConfiguration> m_filesToProcess;
|
QList<SourceFileConfiguration> m_filesToProcess;
|
||||||
int m_initialFilesToProcessSize;
|
int m_initialFilesToProcessSize;
|
||||||
int m_runningProcesses;
|
int m_runningProcesses;
|
||||||
};
|
};
|
||||||
|
@@ -40,14 +40,14 @@ static QString finishedDueToCrash()
|
|||||||
|
|
||||||
static QStringList constructCommandLineArguments(const QString &filePath,
|
static QStringList constructCommandLineArguments(const QString &filePath,
|
||||||
const QString &logFile,
|
const QString &logFile,
|
||||||
const QStringList &definesAndIncludes)
|
const QStringList &options)
|
||||||
{
|
{
|
||||||
QStringList arguments = QStringList()
|
QStringList arguments = QStringList()
|
||||||
<< QLatin1String("--analyze")
|
<< QLatin1String("--analyze")
|
||||||
<< QLatin1String("-o")
|
<< QLatin1String("-o")
|
||||||
<< logFile
|
<< logFile
|
||||||
;
|
;
|
||||||
arguments += definesAndIncludes;
|
arguments += options;
|
||||||
arguments << filePath;
|
arguments << filePath;
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
@@ -88,16 +88,18 @@ ClangStaticAnalyzerRunner::~ClangStaticAnalyzerRunner()
|
|||||||
m_process.kill();
|
m_process.kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClangStaticAnalyzerRunner::run(const QString &filePath, const QStringList &definesAndIncludes)
|
bool ClangStaticAnalyzerRunner::run(const QString &filePath, const QStringList &compilerOptions)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!m_clangExecutable.isEmpty(), return false);
|
QTC_ASSERT(!m_clangExecutable.isEmpty(), return false);
|
||||||
|
QTC_CHECK(!compilerOptions.contains(QLatin1String("-o")));
|
||||||
|
QTC_CHECK(!compilerOptions.contains(filePath));
|
||||||
|
|
||||||
m_processOutput.clear();
|
m_processOutput.clear();
|
||||||
|
|
||||||
m_logFile = createLogFile(filePath);
|
m_logFile = createLogFile(filePath);
|
||||||
QTC_ASSERT(!m_logFile.isEmpty(), return false);
|
QTC_ASSERT(!m_logFile.isEmpty(), return false);
|
||||||
const QStringList arguments = constructCommandLineArguments(filePath, m_logFile,
|
const QStringList arguments = constructCommandLineArguments(filePath, m_logFile,
|
||||||
definesAndIncludes);
|
compilerOptions);
|
||||||
m_commandLine = m_clangExecutable + QLatin1Char(' ') + arguments.join(QLatin1Char(' '));
|
m_commandLine = m_clangExecutable + QLatin1Char(' ') + arguments.join(QLatin1Char(' '));
|
||||||
|
|
||||||
qCDebug(LOG) << "Starting" << m_commandLine;
|
qCDebug(LOG) << "Starting" << m_commandLine;
|
||||||
|
@@ -40,7 +40,8 @@ public:
|
|||||||
QObject *parent = 0);
|
QObject *parent = 0);
|
||||||
~ClangStaticAnalyzerRunner();
|
~ClangStaticAnalyzerRunner();
|
||||||
|
|
||||||
bool run(const QString &filePath, const QStringList &definesAndIncludes = QStringList());
|
// compilerOptions is expected to contain everything except: -o filePath
|
||||||
|
bool run(const QString &filePath, const QStringList &compilerOptions = QStringList());
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void started();
|
void started();
|
||||||
|
Reference in New Issue
Block a user