forked from qt-creator/qt-creator
add support for returning the command's exit status to $$system()
... and make use of it in qtRunLoggedCommand(). Change-Id: I242dfde344f555800cef1f55d3cb85418a93277f Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from qtbase/0eff800e81f3e7f803dffd77737faaed73002ac8)
This commit is contained in:
committed by
Oswald Buddenhagen
parent
9596d6790b
commit
69a4f6c2b5
@@ -441,12 +441,13 @@ void QMakeEvaluator::runProcess(QProcess *proc, const QString &command) const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QByteArray QMakeEvaluator::getCommandOutput(const QString &args) const
|
QByteArray QMakeEvaluator::getCommandOutput(const QString &args, int *exitCode) const
|
||||||
{
|
{
|
||||||
QByteArray out;
|
QByteArray out;
|
||||||
#ifndef QT_BOOTSTRAPPED
|
#ifndef QT_BOOTSTRAPPED
|
||||||
QProcess proc;
|
QProcess proc;
|
||||||
runProcess(&proc, args);
|
runProcess(&proc, args);
|
||||||
|
*exitCode = (proc.exitStatus() == QProcess::NormalExit) ? proc.exitCode() : -1;
|
||||||
QByteArray errout = proc.readAllStandardError();
|
QByteArray errout = proc.readAllStandardError();
|
||||||
# ifdef PROEVALUATOR_FULL
|
# ifdef PROEVALUATOR_FULL
|
||||||
// FIXME: Qt really should have the option to set forwarding per channel
|
// FIXME: Qt really should have the option to set forwarding per channel
|
||||||
@@ -476,7 +477,12 @@ QByteArray QMakeEvaluator::getCommandOutput(const QString &args) const
|
|||||||
break;
|
break;
|
||||||
out += QByteArray(buff, read_in);
|
out += QByteArray(buff, read_in);
|
||||||
}
|
}
|
||||||
QT_PCLOSE(proc);
|
int ec = QT_PCLOSE(proc);
|
||||||
|
# ifdef Q_OS_WIN
|
||||||
|
*exitCode = ec >= 0 ? ec : -1;
|
||||||
|
# else
|
||||||
|
*exitCode = WIFEXITED(ec) ? WEXITSTATUS(ec) : -1;
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
# ifdef Q_OS_WIN
|
# ifdef Q_OS_WIN
|
||||||
out.replace("\r\n", "\n");
|
out.replace("\r\n", "\n");
|
||||||
@@ -866,8 +872,8 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
|
|||||||
break;
|
break;
|
||||||
case E_SYSTEM:
|
case E_SYSTEM:
|
||||||
if (!m_skipLevel) {
|
if (!m_skipLevel) {
|
||||||
if (args.count() < 1 || args.count() > 2) {
|
if (args.count() < 1 || args.count() > 3) {
|
||||||
evalError(fL1S("system(execute) requires one or two arguments."));
|
evalError(fL1S("system(command, [mode], [stsvar]) requires one to three arguments."));
|
||||||
} else {
|
} else {
|
||||||
bool blob = false;
|
bool blob = false;
|
||||||
bool lines = false;
|
bool lines = false;
|
||||||
@@ -881,7 +887,12 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand(
|
|||||||
else if (!m_tmp2.compare(QLatin1String("lines"), Qt::CaseInsensitive))
|
else if (!m_tmp2.compare(QLatin1String("lines"), Qt::CaseInsensitive))
|
||||||
lines = true;
|
lines = true;
|
||||||
}
|
}
|
||||||
QByteArray bytes = getCommandOutput(args.at(0).toQString(m_tmp2));
|
int exitCode;
|
||||||
|
QByteArray bytes = getCommandOutput(args.at(0).toQString(m_tmp2), &exitCode);
|
||||||
|
if (args.count() > 2 && !args.at(2).isEmpty()) {
|
||||||
|
m_valuemapStack.top()[args.at(2).toKey()] =
|
||||||
|
ProStringList(ProString(QString::number(exitCode)));
|
||||||
|
}
|
||||||
if (lines) {
|
if (lines) {
|
||||||
QTextStream stream(bytes);
|
QTextStream stream(bytes);
|
||||||
while (!stream.atEnd())
|
while (!stream.atEnd())
|
||||||
|
@@ -236,7 +236,7 @@ public:
|
|||||||
#ifndef QT_BOOTSTRAPPED
|
#ifndef QT_BOOTSTRAPPED
|
||||||
void runProcess(QProcess *proc, const QString &command) const;
|
void runProcess(QProcess *proc, const QString &command) const;
|
||||||
#endif
|
#endif
|
||||||
QByteArray getCommandOutput(const QString &args) const;
|
QByteArray getCommandOutput(const QString &args, int *exitCode) const;
|
||||||
|
|
||||||
QMakeEvaluator *m_caller;
|
QMakeEvaluator *m_caller;
|
||||||
#ifdef PROEVALUATOR_CUMULATIVE
|
#ifdef PROEVALUATOR_CUMULATIVE
|
||||||
|
Reference in New Issue
Block a user