ProjectManager: Add convenience Task subclasses

For Compile, BuildSystem and Deployment. Unclutters user code and reduces
binary size.

Change-Id: Ia18e917bb411754162e9f4ec6056d752a020bb50
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2020-01-15 08:56:11 +01:00
parent 7e19d1af7c
commit 0334b6e491
56 changed files with 1233 additions and 1548 deletions

View File

@@ -29,8 +29,10 @@
#include <projectexplorer/projectexplorerconstants.h>
using namespace CMakeProjectManager;
using namespace ProjectExplorer;
using namespace Utils;
namespace CMakeProjectManager {
const char COMMON_ERROR_PATTERN[] = "^CMake Error at (.*):([0-9]*)( \\((.*)\\))?:";
const char NEXT_SUBERROR_PATTERN[] = "^CMake Error in (.*):";
@@ -76,16 +78,15 @@ void CMakeParser::stdError(const QString &line)
QDir::fromNativeSeparators(m_commonError.cap(1)))
: QDir::fromNativeSeparators(m_commonError.cap(1));
m_lastTask = Task(Task::Error,
QString(),
Utils::FilePath::fromUserInput(path),
m_commonError.cap(2).toInt(),
Constants::TASK_CATEGORY_BUILDSYSTEM);
m_lastTask = BuildSystemTask(Task::Error,
QString(),
FilePath::fromUserInput(path),
m_commonError.cap(2).toInt());
m_lines = 1;
return;
} else if (m_nextSubError.indexIn(trimmedLine) != -1) {
m_lastTask = Task(Task::Error, QString(), Utils::FilePath::fromUserInput(m_nextSubError.cap(1)), -1,
Constants::TASK_CATEGORY_BUILDSYSTEM);
m_lastTask = BuildSystemTask(Task::Error, QString(),
FilePath::fromUserInput(m_nextSubError.cap(1)));
m_lines = 1;
return;
} else if (trimmedLine.startsWith(QLatin1String(" ")) && !m_lastTask.isNull()) {
@@ -97,12 +98,12 @@ void CMakeParser::stdError(const QString &line)
} else if (trimmedLine.endsWith(QLatin1String("in cmake code at"))) {
m_expectTripleLineErrorData = LINE_LOCATION;
doFlush();
m_lastTask = Task(trimmedLine.contains(QLatin1String("Error")) ? Task::Error : Task::Warning,
QString(), Utils::FilePath(), -1, Constants::TASK_CATEGORY_BUILDSYSTEM);
const Task::TaskType type =
trimmedLine.contains(QLatin1String("Error")) ? Task::Error : Task::Warning;
m_lastTask = BuildSystemTask(type, QString());
return;
} else if (trimmedLine.startsWith("CMake Error: ")) {
m_lastTask = Task(Task::Error, trimmedLine.mid(13),
Utils::FilePath(), -1, Constants::TASK_CATEGORY_BUILDSYSTEM);
m_lastTask = BuildSystemTask(Task::Error, trimmedLine.mid(13));
m_lines = 1;
return;
} else if (trimmedLine.startsWith("-- ") || trimmedLine.startsWith(" * ")) {
@@ -148,6 +149,8 @@ void CMakeParser::doFlush()
m_lines = 0;
}
} // CMakeProjectManager
#ifdef WITH_TESTS
#include "cmakeprojectplugin.h"
@@ -155,6 +158,8 @@ void CMakeParser::doFlush()
#include <QTest>
namespace CMakeProjectManager {
void Internal::CMakeProjectPlugin::testCMakeParser_data()
{
QTest::addColumn<QString>("input");
@@ -164,8 +169,6 @@ void Internal::CMakeProjectPlugin::testCMakeParser_data()
QTest::addColumn<Tasks>("tasks");
QTest::addColumn<QString>("outputLines");
const Core::Id categoryBuild = Constants::TASK_CATEGORY_BUILDSYSTEM;
// negative tests
QTest::newRow("pass-through stdout")
<< QString::fromLatin1("Sometext") << OutputParserTester::STDOUT
@@ -193,14 +196,14 @@ void Internal::CMakeProjectPlugin::testCMakeParser_data()
<< OutputParserTester::STDERR
<< QString() << QString()
<< (Tasks()
<< Task(Task::Error,
QLatin1String("Cannot find source file: unknownFile.qml Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx"),
Utils::FilePath::fromUserInput(QLatin1String("src/1/app/CMakeLists.txt")), 70,
categoryBuild)
<< Task(Task::Error,
QLatin1String("Cannot find source file: CMakeLists.txt2 Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx"),
Utils::FilePath::fromUserInput(QLatin1String("src/1/app/CMakeLists.txt")), -1,
categoryBuild))
<< BuildSystemTask(Task::Error,
"Cannot find source file: unknownFile.qml Tried extensions "
".c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx",
FilePath::fromUserInput("src/1/app/CMakeLists.txt"), 70)
<< BuildSystemTask(Task::Error,
"Cannot find source file: CMakeLists.txt2 Tried extensions "
".c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx",
FilePath::fromUserInput("src/1/app/CMakeLists.txt"), -1))
<< QString();
QTest::newRow("add subdirectory")
@@ -209,10 +212,9 @@ void Internal::CMakeProjectPlugin::testCMakeParser_data()
<< OutputParserTester::STDERR
<< QString() << QString()
<< (Tasks()
<< Task(Task::Error,
QLatin1String("add_subdirectory given source \"app1\" which is not an existing directory."),
Utils::FilePath::fromUserInput(QLatin1String("src/1/CMakeLists.txt")), 8,
categoryBuild))
<< BuildSystemTask(Task::Error,
"add_subdirectory given source \"app1\" which is not an existing directory.",
FilePath::fromUserInput("src/1/CMakeLists.txt"), 8))
<< QString();
QTest::newRow("unknown command")
@@ -221,10 +223,9 @@ void Internal::CMakeProjectPlugin::testCMakeParser_data()
<< OutputParserTester::STDERR
<< QString() << QString()
<< (Tasks()
<< Task(Task::Error,
QLatin1String("Unknown CMake command \"i_am_wrong_command\"."),
Utils::FilePath::fromUserInput(QLatin1String("src/1/CMakeLists.txt")), 8,
categoryBuild))
<< BuildSystemTask(Task::Error,
"Unknown CMake command \"i_am_wrong_command\".",
FilePath::fromUserInput("src/1/CMakeLists.txt"), 8))
<< QString();
QTest::newRow("incorrect arguments")
@@ -233,10 +234,9 @@ void Internal::CMakeProjectPlugin::testCMakeParser_data()
<< OutputParserTester::STDERR
<< QString() << QString()
<< (Tasks()
<< Task(Task::Error,
QLatin1String("message called with incorrect number of arguments"),
Utils::FilePath::fromUserInput(QLatin1String("src/1/CMakeLists.txt")), 8,
categoryBuild))
<< BuildSystemTask(Task::Error,
"message called with incorrect number of arguments",
FilePath::fromUserInput("src/1/CMakeLists.txt"), 8))
<< QString();
QTest::newRow("cmake error")
@@ -247,10 +247,9 @@ void Internal::CMakeProjectPlugin::testCMakeParser_data()
<< OutputParserTester::STDERR
<< QString() << QString()
<< (Tasks()
<< Task(Task::Error,
QLatin1String("Parse error. Expected \"(\", got newline with text \"\n\"."),
Utils::FilePath::fromUserInput(QLatin1String("/test/path/CMakeLists.txt")), 9,
categoryBuild))
<< BuildSystemTask(Task::Error,
"Parse error. Expected \"(\", got newline with text \"\n\".",
FilePath::fromUserInput("/test/path/CMakeLists.txt"), 9))
<< QString();
QTest::newRow("cmake error2")
@@ -258,11 +257,11 @@ void Internal::CMakeProjectPlugin::testCMakeParser_data()
"Missing variable is:\n"
"CMAKE_MAKE_PROGRAM\n")
<< OutputParserTester::STDERR
<< QString() << QString::fromLatin1("Missing variable is:\nCMAKE_MAKE_PROGRAM\n")
<< QString() << QString("Missing variable is:\nCMAKE_MAKE_PROGRAM\n")
<< (Tasks()
<< Task(Task::Error,
QLatin1String("Error required internal CMake variable not set, cmake may be not be built correctly."),
Utils::FilePath(), -1, categoryBuild))
<< BuildSystemTask(Task::Error,
"Error required internal CMake variable not set, "
"cmake may be not be built correctly."))
<< QString();
QTest::newRow("cmake error at")
@@ -273,10 +272,9 @@ void Internal::CMakeProjectPlugin::testCMakeParser_data()
<< OutputParserTester::STDERR
<< QString() << QString()
<< (Tasks()
<< Task(Task::Error,
QLatin1String("Parse error. Expected \"(\", got newline with text \" \"."),
Utils::FilePath::fromUserInput(QLatin1String("CMakeLists.txt")), 4,
categoryBuild))
<< BuildSystemTask(Task::Error,
"Parse error. Expected \"(\", got newline with text \" \".",
FilePath::fromUserInput("CMakeLists.txt"), 4))
<< QString();
QTest::newRow("cmake warning")
@@ -286,10 +284,9 @@ void Internal::CMakeProjectPlugin::testCMakeParser_data()
<< OutputParserTester::STDERR
<< QString() << QString()
<< (Tasks()
<< Task(Task::Warning,
QLatin1String("Argument not separated from preceding token by whitespace."),
Utils::FilePath::fromUserInput(QLatin1String("/test/path/CMakeLists.txt")), 9,
categoryBuild))
<< BuildSystemTask(Task::Warning,
"Argument not separated from preceding token by whitespace.",
FilePath::fromUserInput("/test/path/CMakeLists.txt"), 9))
<< QString();
QTest::newRow("eat normal CMake output")
<< QString::fromLatin1("-- Qt5 install prefix: /usr/lib\n"
@@ -313,4 +310,6 @@ void Internal::CMakeProjectPlugin::testCMakeParser()
outputLines);
}
} // CMakeProjectManager
#endif