Commit 2da28cea authored by hjk's avatar hjk
Browse files

Debugger: Remove plugin dependency from dumper autotest

Change-Id: Id6d3cf6299af53cbf6910f545dee3820e90a7746
Reviewed-by: default avatarhjk <>
parent 6fb94a7b
QTC_LIB_DEPENDS += cplusplus
......@@ -32,12 +32,15 @@
#include "watchutils.h"
#include <cplusplus/CppRewriter.h>
#include <projectexplorer/abstractmsvctoolchain.h>
#include <utils/environment.h>
#include <utils/qtcprocess.h>
#include <utils/fileutils.h>
#include <utils/synchronousprocess.h>
#include <QtTest>
#include "temporarydir.h"
#include <QtTest>
#if QT_VERSION >= 0x050000
#define MSKIP_SINGLE(x) QSKIP(x)
......@@ -48,6 +51,98 @@ using namespace Debugger;
using namespace Utils;
using namespace Internal;
// Copied from abstractmsvctoolchain.cpp to avoid plugin dependency.
static bool generateEnvironmentSettings(Utils::Environment &env,
const QString &batchFile,
const QString &batchArgs,
QMap<QString, QString> &envPairs)
// Create a temporary file name for the output. Use a temporary file here
// as I don't know another way to do this in Qt...
// Note, can't just use a QTemporaryFile all the way through as it remains open
// internally so it can't be streamed to later.
QString tempOutFile;
QTemporaryFile* pVarsTempFile = new QTemporaryFile(QDir::tempPath() + QLatin1String("/XXXXXX.txt"));
tempOutFile = pVarsTempFile->fileName();
delete pVarsTempFile;
// Create a batch file to create and save the env settings
Utils::TempFileSaver saver(QDir::tempPath() + QLatin1String("/XXXXXX.bat"));
QByteArray call = "call ";
call += Utils::QtcProcess::quoteArg(batchFile).toLocal8Bit();
if (!batchArgs.isEmpty()) {
call += ' ';
call += batchArgs.toLocal8Bit();
saver.write(call + "\r\n");
const QByteArray redirect = "set > " + Utils::QtcProcess::quoteArg(
QDir::toNativeSeparators(tempOutFile)).toLocal8Bit() + "\r\n";
if (!saver.finalize()) {
qWarning("%s: %s", Q_FUNC_INFO, qPrintable(saver.errorString()));
return false;
Utils::QtcProcess run;
// As of WinSDK 7.1, there is logic preventing the path from being set
// correctly if "ORIGINALPATH" is already set. That can cause problems
// if Creator is launched within a session set up by setenv.cmd.
const QString cmdPath = QString::fromLocal8Bit(qgetenv("COMSPEC"));
// Windows SDK setup scripts require command line switches for environment expansion.
QString cmdArguments = QLatin1String(" /E:ON /V:ON /c \"");
cmdArguments += QDir::toNativeSeparators(saver.fileName());
cmdArguments += QLatin1Char('"');
run.setCommand(cmdPath, cmdArguments);
if (!run.waitForStarted()) {
qWarning("%s: Unable to run '%s': %s", Q_FUNC_INFO, qPrintable(batchFile),
return false;
if (!run.waitForFinished()) {
qWarning("%s: Timeout running '%s'", Q_FUNC_INFO, qPrintable(batchFile));
return false;
// The SDK/MSVC scripts do not return exit codes != 0. Check on stdout.
const QByteArray stdOut = run.readAllStandardOutput();
if (!stdOut.isEmpty() && (stdOut.contains("Unknown") || stdOut.contains("Error")))
qWarning("%s: '%s' reports:\n%s", Q_FUNC_INFO, call.constData(), stdOut.constData());
// Now parse the file to get the environment settings
QFile varsFile(tempOutFile);
if (!
return false;
QRegExp regexp(QLatin1String("(\\w*)=(.*)"));
while (!varsFile.atEnd()) {
const QString line = QString::fromLocal8Bit(varsFile.readLine()).trimmed();
if (regexp.exactMatch(line)) {
const QString varName = regexp.cap(1);
const QString varValue = regexp.cap(2);
if (!varValue.isEmpty())
envPairs.insert(varName, varValue);
// Tidy up and remove the file
return true;
static QByteArray noValue = "\001";
static QString toHex(const QString &str)
......@@ -452,9 +547,7 @@ void tst_Dumpers::initTestCase()
} else if (m_debuggerEngine == DumpTestCdbEngine) {
QByteArray envBat = qgetenv("QTC_MSVC_ENV_BAT");
QMap <QString, QString> envPairs;
utilsEnv, QString::fromLatin1(envBat), QString(), envPairs));
QVERIFY(generateEnvironmentSettings(utilsEnv, QString::fromLatin1(envBat), QString(), envPairs));
for (QMap<QString,QString>::const_iterator envIt = envPairs.begin(); envIt!=envPairs.end(); ++envIt)
utilsEnv.set(envIt.key(), envIt.value());
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment