Run the analyzer within the build environment.

This is especially important for clang-cl, which requires the environment
set by e.g. vcvars32.bat [1].

[1] http://clang.llvm.org/docs/UsersManual.html#clang-cl

Change-Id: If319bb94752bbef9207581c50173dde99af007bc
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2015-04-15 11:48:26 +02:00
parent ef79615fe5
commit 19f4072142
5 changed files with 24 additions and 3 deletions

View File

@@ -209,6 +209,13 @@ AnalyzeUnits ClangStaticAnalyzerRunControl::unitsToAnalyze()
m_wordWidth);
}
static QDebug operator<<(QDebug debug, const Utils::Environment &environment)
{
foreach (const QString &entry, environment.toStringList())
debug << "\n " << entry;
return debug;
}
bool ClangStaticAnalyzerRunControl::startEngine()
{
emit starting(this);
@@ -271,6 +278,7 @@ bool ClangStaticAnalyzerRunControl::startEngine()
m_progress.reportStarted();
// Start process(es)
qCDebug(LOG) << "Environment:" << startParameters().environment;
m_runners.clear();
const int parallelRuns = ClangStaticAnalyzerSettings::instance()->simultaneousProcesses();
QTC_ASSERT(parallelRuns >= 1, emit finished(); return false);
@@ -335,7 +343,10 @@ ClangStaticAnalyzerRunner *ClangStaticAnalyzerRunControl::createRunner()
QTC_ASSERT(!m_clangLogFileDir.isEmpty(), return 0);
ClangStaticAnalyzerRunner *runner
= new ClangStaticAnalyzerRunner(m_clangExecutable, m_clangLogFileDir, this);
= new ClangStaticAnalyzerRunner(m_clangExecutable,
m_clangLogFileDir,
startParameters().environment,
this);
connect(runner, &ClangStaticAnalyzerRunner::finishedWithSuccess,
this, &ClangStaticAnalyzerRunControl::onRunnerFinishedWithSuccess);
connect(runner, &ClangStaticAnalyzerRunner::finishedWithFailure,

View File

@@ -25,6 +25,7 @@
#include <cpptools/cppmodelmanager.h>
#include <cpptools/cppprojects.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/gcctoolchain.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/kitinformation.h>
@@ -99,6 +100,10 @@ RunControl *ClangStaticAnalyzerRunControlFactory::create(RunConfiguration *runCo
AnalyzerStartParameters sp;
sp.runMode = runMode;
sp.startMode = StartLocal;
BuildConfiguration * const buildConfiguration = target->activeBuildConfiguration();
QTC_ASSERT(buildConfiguration, return 0);
sp.environment = buildConfiguration->environment();
return AnalyzerManager::createRunControl(sp, runConfiguration);
}

View File

@@ -64,6 +64,7 @@ QString finishedWithBadExitCode(int exitCode)
ClangStaticAnalyzerRunner::ClangStaticAnalyzerRunner(const QString &clangExecutable,
const QString &clangLogFileDir,
const Utils::Environment &environment,
QObject *parent)
: QObject(parent)
, m_clangExecutable(clangExecutable)
@@ -73,6 +74,7 @@ ClangStaticAnalyzerRunner::ClangStaticAnalyzerRunner(const QString &clangExecuta
QTC_CHECK(!m_clangLogFileDir.isEmpty());
m_process.setProcessChannelMode(QProcess::MergedChannels);
m_process.setProcessEnvironment(environment.toProcessEnvironment());
m_process.setWorkingDirectory(m_clangLogFileDir); // Current clang-cl puts log file into working dir.
connect(&m_process, &QProcess::started,
this, &ClangStaticAnalyzerRunner::onProcessStarted);

View File

@@ -37,6 +37,7 @@ class ClangStaticAnalyzerRunner : public QObject
public:
ClangStaticAnalyzerRunner(const QString &clangExecutable,
const QString &clangLogFileDir,
const Utils::Environment &environment,
QObject *parent = 0);
~ClangStaticAnalyzerRunner();

View File

@@ -141,7 +141,8 @@ void ClangStaticAnalyzerRunnerTest::runWithTestCodeGeneratedOneIssue()
QTemporaryDir temporaryDir(QDir::tempPath() + QLatin1String("/qtc-clangstaticanalyzer-XXXXXX"));
QVERIFY(temporaryDir.isValid());
ClangStaticAnalyzerRunner runner(QLatin1String("clang"), temporaryDir.path());
ClangStaticAnalyzerRunner runner(QLatin1String("clang"), temporaryDir.path(),
Utils::Environment::systemEnvironment());
ClangStaticAnalyzerRunnerSignalTester st(&runner);
QVERIFY(runner.run(testFilePath));
@@ -153,7 +154,8 @@ void ClangStaticAnalyzerRunnerTest::runWithNonExistentFileToAnalyze()
{
QTemporaryDir temporaryDir(QDir::tempPath() + QLatin1String("/qtc-clangstaticanalyzer-XXXXXX"));
QVERIFY(temporaryDir.isValid());
ClangStaticAnalyzerRunner runner(QLatin1String("clang"), temporaryDir.path());
ClangStaticAnalyzerRunner runner(QLatin1String("clang"), temporaryDir.path(),
Utils::Environment::systemEnvironment());
ClangStaticAnalyzerRunnerSignalTester st(&runner);
QVERIFY(runner.run(QLatin1String("not.existing.file.111")));