diff options
-rw-r--r-- | mkspecs/features/configure_base.prf | 9 | ||||
-rw-r--r-- | qmake/doc/src/qmake-manual.qdoc | 7 | ||||
-rw-r--r-- | qmake/library/qmakebuiltins.cpp | 21 | ||||
-rw-r--r-- | qmake/library/qmakeevaluator.h | 2 | ||||
-rw-r--r-- | tests/auto/tools/qmakelib/evaltest.cpp | 4 |
5 files changed, 28 insertions, 15 deletions
diff --git a/mkspecs/features/configure_base.prf b/mkspecs/features/configure_base.prf index fd1730741a..3397a7703e 100644 --- a/mkspecs/features/configure_base.prf +++ b/mkspecs/features/configure_base.prf @@ -32,16 +32,13 @@ defineTest(qtLog) { defineTest(qtRunLoggedCommand) { qtLog($$1) - write_file($${QMAKE_CONFIG_LOG}.part, "") - result = false - system("$$1 > \"$${QMAKE_CONFIG_LOG}.part\" 2>&1"): result = true - - output = $$cat($${QMAKE_CONFIG_LOG}.part, blob) + output = $$system("$$1 2>&1", blob, result) write_file($${QMAKE_CONFIG_LOG}, output, append) $$QMAKE_CONFIG_VERBOSE: log($$output) - return($$result) + !equals(result, 0): return(false) + return(true) } isEmpty(QMAKE_CONFIG_TESTS_DIR): QMAKE_CONFIG_TESTS_DIR = $$_PRO_FILE_PWD_/config.tests diff --git a/qmake/doc/src/qmake-manual.qdoc b/qmake/doc/src/qmake-manual.qdoc index 38e80f7a2d..68538cabe3 100644 --- a/qmake/doc/src/qmake-manual.qdoc +++ b/qmake/doc/src/qmake-manual.qdoc @@ -3138,7 +3138,7 @@ See also \l{fn_size}{size()}. - \section2 system(command[, mode]) + \section2 system(command[, mode[, stsvar]]) You can use this variant of the \c system function to obtain stdout from the command and assign it to a variable. @@ -3147,6 +3147,11 @@ \snippet code/doc_src_qmake-manual.pro 72 + If you pass \c stsvar, the command's exit status will be stored in that + variable. If the command crashes, the status will be -1, otherwise a + non-negative exit code of the command's choosing. Usually, comparing + the status with zero (success) is sufficient. + See also the test variant of \l{system(command)}{system()}. \section2 system_path(path) diff --git a/qmake/library/qmakebuiltins.cpp b/qmake/library/qmakebuiltins.cpp index ac3a866848..0cc3b52458 100644 --- a/qmake/library/qmakebuiltins.cpp +++ b/qmake/library/qmakebuiltins.cpp @@ -450,12 +450,13 @@ void QMakeEvaluator::runProcess(QProcess *proc, const QString &command) const } #endif -QByteArray QMakeEvaluator::getCommandOutput(const QString &args) const +QByteArray QMakeEvaluator::getCommandOutput(const QString &args, int *exitCode) const { QByteArray out; #ifndef QT_BOOTSTRAPPED QProcess proc; runProcess(&proc, args); + *exitCode = (proc.exitStatus() == QProcess::NormalExit) ? proc.exitCode() : -1; QByteArray errout = proc.readAllStandardError(); # ifdef PROEVALUATOR_FULL // FIXME: Qt really should have the option to set forwarding per channel @@ -483,7 +484,12 @@ QByteArray QMakeEvaluator::getCommandOutput(const QString &args) const break; 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 out.replace("\r\n", "\n"); @@ -871,8 +877,8 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand( break; case E_SYSTEM: if (!m_skipLevel) { - if (args.count() < 1 || args.count() > 2) { - evalError(fL1S("system(execute) requires one or two arguments.")); + if (args.count() < 1 || args.count() > 3) { + evalError(fL1S("system(command, [mode], [stsvar]) requires one to three arguments.")); } else { bool blob = false; bool lines = false; @@ -885,7 +891,12 @@ ProStringList QMakeEvaluator::evaluateBuiltinExpand( else if (!args.at(1).compare(QLatin1String("lines"), Qt::CaseInsensitive)) 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) { QTextStream stream(bytes); while (!stream.atEnd()) diff --git a/qmake/library/qmakeevaluator.h b/qmake/library/qmakeevaluator.h index eddabe39a0..3f2a22c567 100644 --- a/qmake/library/qmakeevaluator.h +++ b/qmake/library/qmakeevaluator.h @@ -240,7 +240,7 @@ public: #ifndef QT_BOOTSTRAPPED void runProcess(QProcess *proc, const QString &command) const; #endif - QByteArray getCommandOutput(const QString &args) const; + QByteArray getCommandOutput(const QString &args, int *exitCode) const; QMakeEvaluator *m_caller; #ifdef PROEVALUATOR_CUMULATIVE diff --git a/tests/auto/tools/qmakelib/evaltest.cpp b/tests/auto/tools/qmakelib/evaltest.cpp index ffdf9294b8..1cd5c71531 100644 --- a/tests/auto/tools/qmakelib/evaltest.cpp +++ b/tests/auto/tools/qmakelib/evaltest.cpp @@ -1326,9 +1326,9 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir) << true; QTest::newRow("$$system(): bad number of arguments") - << "VAR = $$system(1, 2, 3)" + << "VAR = $$system(1, 2, 3, 4)" << "VAR =" - << "##:1: system(execute) requires one or two arguments." + << "##:1: system(command, [mode], [stsvar]) requires one to three arguments." << true; QTest::newRow("$$unique()") |