summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2015-03-17 11:04:52 +0100
committerJoerg Bornemann <joerg.bornemann@theqtcompany.com>2015-03-17 15:14:29 +0000
commit7bbe5cb1a3a9af08feda8f9a173fc354b8a18f4b (patch)
tree9f2b267f2bf666dd1f6c3f87e65f57b1891ecd27
parentac71a80c5a9dbf83f80b1ad83d9b753694b6af05 (diff)
fix ignoring exit codes greater than 255
Having a command prefixed with - should ignore the exit code. However, only exit codes <= 255 were properly ignored. The exit code type is unsigned int in MSVC land. Change-Id: I352f0f068aaed5afc18081a3125d46eeb5094d44 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
-rw-r--r--src/jomlib/commandexecutor.cpp2
-rw-r--r--src/jomlib/makefile.cpp8
-rw-r--r--src/jomlib/makefile.h2
-rw-r--r--src/jomlib/parser.cpp4
-rw-r--r--tests/makefiles/blackbox/ignoreExitCodes/test.mk20
-rw-r--r--tests/tests.cpp15
6 files changed, 34 insertions, 17 deletions
diff --git a/src/jomlib/commandexecutor.cpp b/src/jomlib/commandexecutor.cpp
index 6aa971e..99c8832 100644
--- a/src/jomlib/commandexecutor.cpp
+++ b/src/jomlib/commandexecutor.cpp
@@ -121,7 +121,7 @@ void CommandExecutor::onProcessFinished(int exitCode, Process::ExitStatus exitSt
exitCode = 2;
const Command &currentCommand = m_pTarget->m_commands.at(m_currentCommandIdx);
- if (exitCode > currentCommand.m_maxExitCode) {
+ if (static_cast<unsigned int>(exitCode) > currentCommand.m_maxExitCode) {
QByteArray msg = "jom: ";
msg += QDir::toNativeSeparators(QDir::currentPath() + QDir::separator()).toLocal8Bit();
msg += m_pTarget->makefile()->fileName().toLocal8Bit();
diff --git a/src/jomlib/makefile.cpp b/src/jomlib/makefile.cpp
index ae6bdf0..6ec1e07 100644
--- a/src/jomlib/makefile.cpp
+++ b/src/jomlib/makefile.cpp
@@ -21,10 +21,13 @@
#include "makefile.h"
#include "exception.h"
#include "options.h"
+
#include <QFileInfo>
#include <QDebug>
#include <QDir>
+#include <limits>
+
namespace NMakeFile {
InlineFile::InlineFile()
@@ -76,13 +79,14 @@ void Command::evaluateModifiers()
if (firstChar == QLatin1Char('-')) {
m_commandLine.remove(0, 1);
int i = 0;
+ // Read the (optional) number after the minus.
while (i < m_commandLine.length() && m_commandLine.at(i).isDigit())
++i;
if (i > 0) {
- m_maxExitCode = (unsigned char)m_commandLine.mid(0, i).toInt();
+ m_maxExitCode = m_commandLine.mid(0, i).toUInt();
m_commandLine.remove(0, i);
} else {
- m_maxExitCode = 255;
+ m_maxExitCode = std::numeric_limits<unsigned int>::max();
}
} else if (firstChar == QLatin1Char('@')) {
m_commandLine.remove(0, 1);
diff --git a/src/jomlib/makefile.h b/src/jomlib/makefile.h
index 35ea55b..3fbf405 100644
--- a/src/jomlib/makefile.h
+++ b/src/jomlib/makefile.h
@@ -52,7 +52,7 @@ public:
QString m_commandLine;
QList<InlineFile*> m_inlineFiles;
- unsigned char m_maxExitCode; // greatest allowed exit code
+ unsigned int m_maxExitCode; // greatest allowed exit code
bool m_silent;
bool m_singleExecution; // Execute this command for each dependent, if the command contains $** or $?.
};
diff --git a/src/jomlib/parser.cpp b/src/jomlib/parser.cpp
index 2a9c025..b362d65 100644
--- a/src/jomlib/parser.cpp
+++ b/src/jomlib/parser.cpp
@@ -28,6 +28,8 @@
#include <QDir>
#include <QDirIterator>
+#include <limits>
+
namespace NMakeFile {
Parser::Parser()
@@ -469,7 +471,7 @@ void Parser::parseCommandLine(const QString& cmdLine, QList<Command>& commands,
{
commands.append(Command());
Command& cmd = commands.last();
- if (m_ignoreExitCodes) cmd.m_maxExitCode = 255;
+ if (m_ignoreExitCodes) cmd.m_maxExitCode = std::numeric_limits<unsigned int>::max();
cmd.m_silent = m_silentCommands;
if (inferenceRule) {
diff --git a/tests/makefiles/blackbox/ignoreExitCodes/test.mk b/tests/makefiles/blackbox/ignoreExitCodes/test.mk
index 35dee3d..11d1d4a 100644
--- a/tests/makefiles/blackbox/ignoreExitCodes/test.mk
+++ b/tests/makefiles/blackbox/ignoreExitCodes/test.mk
@@ -1,11 +1,17 @@
# test ignore exit codes in make files
-#
-# http://msdn.microsoft.com/en-us/library/1whxt45w.aspx
-all: test_ignoreExitCode
- @echo ---SUCCESS---
+test1: testNonexistentCommand testExitCode1 testExitCode2
+ @echo ---SUCCESS---
-test_ignoreExitCode:
- -nonexistent_command
- @echo Failing command was properly ignored
+testNonexistentCommand:
+ -nonexistent_command 2>NUL
+testExitCode1:
+ -cmd /k exit 1
+
+testExitCode2:
+ -1cmd /k exit 1
+
+# target test2 is supposed to fail
+test2:
+ -6cmd /k exit 7
diff --git a/tests/tests.cpp b/tests/tests.cpp
index a497101..30fbb54 100644
--- a/tests/tests.cpp
+++ b/tests/tests.cpp
@@ -33,6 +33,8 @@
#include <options.h>
#include <exception.h>
+#include <limits>
+
using namespace NMakeFile;
void Tests::initTestCase()
@@ -361,7 +363,7 @@ void Tests::dotDirectives()
QVERIFY(target != 0);
QCOMPARE(target->m_commands.count(), 2);
cmd = target->m_commands.takeFirst();
- QCOMPARE(int(cmd.m_maxExitCode), 255);
+ QCOMPARE(cmd.m_maxExitCode, std::numeric_limits<unsigned int>::max());
target = mkfile->target(QLatin1String("ignorance_three"));
QVERIFY(target != 0);
@@ -580,13 +582,13 @@ void Tests::commandModifiers()
QCOMPARE(cmd.m_silent, true);
cmd = target->m_commands.at(1);
- QCOMPARE((int)cmd.m_maxExitCode, 255);
+ QCOMPARE(cmd.m_maxExitCode, std::numeric_limits<unsigned int>::max());
cmd = target->m_commands.at(2);
- QCOMPARE((int)cmd.m_maxExitCode, 5);
+ QCOMPARE(cmd.m_maxExitCode, 5u);
cmd = target->m_commands.at(3);
- QCOMPARE((int)cmd.m_maxExitCode, 15);
+ QCOMPARE(cmd.m_maxExitCode, 15u);
cmd = target->m_commands.at(4);
QCOMPARE(cmd.m_singleExecution, true);
@@ -1101,7 +1103,10 @@ void Tests::ignoreExitCodes()
QVERIFY(runJom(QStringList() << "/f" << "blackbox\\ignoreExitCodes\\test.mk"));
QCOMPARE(m_jomProcess->exitCode(), 0);
QByteArray output = m_jomProcess->readAllStandardOutput();
- QVERIFY(output.contains("Failing command was properly ignored"));
+ QVERIFY(output.contains("---SUCCESS---"));
+
+ QVERIFY(runJom(QStringList() << "/f" << "blackbox\\ignoreExitCodes\\test.mk" << "test2"));
+ QCOMPARE(m_jomProcess->exitCode(), 2);
}
void Tests::inlineFiles()