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

@@ -281,9 +281,8 @@ void BuildDirManager::setParametersAndRequestParse(const BuildDirParameters &par
{
qCDebug(cmakeBuildDirManagerLog) << "setting parameters and requesting reparse";
if (!parameters.cmakeTool()) {
TaskHub::addTask(Task::Error,
tr("The kit needs to define a CMake tool to parse this project."),
ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
TaskHub::addTask(BuildSystemTask(Task::Error, tr(
"The kit needs to define a CMake tool to parse this project.")));
return;
}
QTC_ASSERT(parameters.isValid(), return );

View File

@@ -141,32 +141,26 @@ bool CMakeBuildStep::init()
canInit = false;
}
if (bc && !bc->isEnabled()) {
emit addTask(Task(Task::Error,
QCoreApplication::translate("CMakeProjectManager::CMakeBuildStep",
"The build configuration is currently disabled."),
Utils::FilePath(), -1, ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
emit addTask(BuildSystemTask(Task::Error,
tr("CMakeProjectManager::CMakeBuildStep")));
canInit = false;
}
CMakeTool *tool = CMakeKitAspect::cmakeTool(target()->kit());
if (!tool || !tool->isValid()) {
emit addTask(Task(Task::Error,
emit addTask(BuildSystemTask(Task::Error,
tr("A CMake tool must be set up for building. "
"Configure a CMake tool in the kit options."),
Utils::FilePath(), -1,
ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
"Configure a CMake tool in the kit options.")));
canInit = false;
}
RunConfiguration *rc = target()->activeRunConfiguration();
if (isCurrentExecutableTarget(m_buildTarget) && (!rc || rc->buildKey().isEmpty())) {
emit addTask(Task(Task::Error,
emit addTask(BuildSystemTask(Task::Error,
QCoreApplication::translate("ProjectExplorer::Task",
"You asked to build the current Run Configuration's build target only, "
"but it is not associated with a build target. "
"Update the Make Step in your build settings."),
Utils::FilePath(), -1,
ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
"Update the Make Step in your build settings.")));
canInit = false;
}
@@ -179,13 +173,11 @@ bool CMakeBuildStep::init()
const Utils::FilePath projectDirectory = bc->target()->project()->projectDirectory();
if (bc->buildDirectory() != projectDirectory) {
if (projectDirectory.pathAppended("CMakeCache.txt").exists()) {
emit addTask(Task(Task::Warning,
emit addTask(BuildSystemTask(Task::Warning,
tr("There is a CMakeCache.txt file in \"%1\", which suggest an "
"in-source build was done before. You are now building in \"%2\", "
"and the CMakeCache.txt file might confuse CMake.")
.arg(projectDirectory.toUserOutput(), bc->buildDirectory().toUserOutput()),
Utils::FilePath(), -1,
ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
.arg(projectDirectory.toUserOutput(), bc->buildDirectory().toUserOutput())));
}
}

View File

@@ -252,9 +252,8 @@ Tasks CMakeKitAspect::validate(const Kit *k) const
if (tool) {
CMakeTool::Version version = tool->version();
if (version.major < 3) {
result << Task(Task::Warning, tr("CMake version %1 is unsupported. Please update to "
"version 3.0 or later.").arg(QString::fromUtf8(version.fullVersion)),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
result << BuildSystemTask(Task::Warning, tr("CMake version %1 is unsupported. Please update to "
"version 3.0 or later.").arg(QString::fromUtf8(version.fullVersion)));
}
}
return result;
@@ -653,41 +652,38 @@ QVariant CMakeGeneratorKitAspect::defaultValue(const Kit *k) const
Tasks CMakeGeneratorKitAspect::validate(const Kit *k) const
{
CMakeTool *tool = CMakeKitAspect::cmakeTool(k);
GeneratorInfo info = generatorInfo(k);
if (!tool)
return {};
Tasks result;
if (tool) {
if (!tool->isValid()) {
result << Task(Task::Warning, tr("CMake Tool is unconfigured, CMake generator will be ignored."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
const auto addWarning = [&result](const QString &desc) {
result << BuildSystemTask(Task::Warning, desc);
};
if (!tool->isValid()) {
addWarning(tr("CMake Tool is unconfigured, CMake generator will be ignored."));
} else {
const GeneratorInfo info = generatorInfo(k);
QList<CMakeTool::Generator> known = tool->supportedGenerators();
auto it = std::find_if(known.constBegin(), known.constEnd(), [info](const CMakeTool::Generator &g) {
return g.matches(info.generator, info.extraGenerator);
});
if (it == known.constEnd()) {
addWarning(tr("CMake Tool does not support the configured generator."));
} else {
QList<CMakeTool::Generator> known = tool->supportedGenerators();
auto it = std::find_if(known.constBegin(), known.constEnd(), [info](const CMakeTool::Generator &g) {
return g.matches(info.generator, info.extraGenerator);
});
if (it == known.constEnd()) {
result << Task(Task::Warning, tr("CMake Tool does not support the configured generator."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
} else {
if (!it->supportsPlatform && !info.platform.isEmpty()) {
result << Task(Task::Warning, tr("Platform is not supported by the selected CMake generator."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
}
if (!it->supportsToolset && !info.toolset.isEmpty()) {
result << Task(Task::Warning, tr("Toolset is not supported by the selected CMake generator."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
}
}
if ((!tool->hasServerMode() && !tool->hasFileApi())
&& info.extraGenerator != "CodeBlocks") {
result << Task(Task::Warning, tr("The selected CMake binary has no server-mode and the CMake "
"generator does not generate a CodeBlocks file. "
"%1 will not be able to parse CMake projects.")
.arg(Core::Constants::IDE_DISPLAY_NAME),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
}
if (!it->supportsPlatform && !info.platform.isEmpty())
addWarning(tr("Platform is not supported by the selected CMake generator."));
if (!it->supportsToolset && !info.toolset.isEmpty())
addWarning(tr("Toolset is not supported by the selected CMake generator."));
}
if (!tool->hasServerMode() && !tool->hasFileApi() && info.extraGenerator != "CodeBlocks") {
addWarning(tr("The selected CMake binary has no server-mode and the CMake "
"generator does not generate a CodeBlocks file. "
"%1 will not be able to parse CMake projects.")
.arg(Core::Constants::IDE_DISPLAY_NAME));
}
}
return result;
}
@@ -982,69 +978,63 @@ Tasks CMakeConfigurationKitAspect::validate(const Kit *k) const
}
Tasks result;
const auto addWarning = [&result](const QString &desc) {
result << BuildSystemTask(Task::Warning, desc);
};
// Validate Qt:
if (qmakePath.isEmpty()) {
if (version && version->isValid() && isQt4) {
result << Task(Task::Warning, tr("CMake configuration has no path to qmake binary set, "
"even though the kit has a valid Qt version."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
addWarning(tr("CMake configuration has no path to qmake binary set, "
"even though the kit has a valid Qt version."));
}
} else {
if (!version || !version->isValid()) {
result << Task(Task::Warning, tr("CMake configuration has a path to a qmake binary set, "
"even though the kit has no valid Qt version."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
addWarning(tr("CMake configuration has a path to a qmake binary set, "
"even though the kit has no valid Qt version."));
} else if (qmakePath != version->qmakeCommand() && isQt4) {
result << Task(Task::Warning, tr("CMake configuration has a path to a qmake binary set "
"that does not match the qmake binary path "
"configured in the Qt version."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
addWarning(tr("CMake configuration has a path to a qmake binary set "
"that does not match the qmake binary path "
"configured in the Qt version."));
}
}
if (version && !qtInstallDirs.contains(version->prefix().toString()) && !isQt4) {
if (version->isValid()) {
result << Task(Task::Warning, tr("CMake configuration has no CMAKE_PREFIX_PATH set "
"that points to the kit Qt version."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
addWarning(tr("CMake configuration has no CMAKE_PREFIX_PATH set "
"that points to the kit Qt version."));
}
}
// Validate Toolchains:
if (tcCPath.isEmpty()) {
if (tcC && tcC->isValid()) {
result << Task(Task::Warning, tr("CMake configuration has no path to a C compiler set, "
"even though the kit has a valid tool chain."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
addWarning(tr("CMake configuration has no path to a C compiler set, "
"even though the kit has a valid tool chain."));
}
} else {
if (!tcC || !tcC->isValid()) {
result << Task(Task::Warning, tr("CMake configuration has a path to a C compiler set, "
"even though the kit has no valid tool chain."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
addWarning(tr("CMake configuration has a path to a C compiler set, "
"even though the kit has no valid tool chain."));
} else if (tcCPath != tcC->compilerCommand()) {
result << Task(Task::Warning, tr("CMake configuration has a path to a C compiler set "
"that does not match the compiler path "
"configured in the tool chain of the kit."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
addWarning(tr("CMake configuration has a path to a C compiler set "
"that does not match the compiler path "
"configured in the tool chain of the kit."));
}
}
if (tcCxxPath.isEmpty()) {
if (tcCxx && tcCxx->isValid()) {
result << Task(Task::Warning, tr("CMake configuration has no path to a C++ compiler set, "
"even though the kit has a valid tool chain."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
addWarning(tr("CMake configuration has no path to a C++ compiler set, "
"even though the kit has a valid tool chain."));
}
} else {
if (!tcCxx || !tcCxx->isValid()) {
result << Task(Task::Warning, tr("CMake configuration has a path to a C++ compiler set, "
"even though the kit has no valid tool chain."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
addWarning(tr("CMake configuration has a path to a C++ compiler set, "
"even though the kit has no valid tool chain."));
} else if (tcCxxPath != tcCxx->compilerCommand()) {
result << Task(Task::Warning, tr("CMake configuration has a path to a C++ compiler set "
"that does not match the compiler path "
"configured in the tool chain of the kit."),
Utils::FilePath(), -1, Core::Id(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM));
addWarning(tr("CMake configuration has a path to a C++ compiler set "
"that does not match the compiler path "
"configured in the tool chain of the kit."));
}
}

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

View File

@@ -225,7 +225,7 @@ void CMakeProcess::handleProcessFinished(int code, QProcess::ExitStatus status)
if (!msg.isEmpty()) {
Core::MessageManager::write(msg);
TaskHub::addTask(Task::Error, msg, ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
TaskHub::addTask(BuildSystemTask(Task::Error, msg));
m_future->reportCanceled();
} else {
m_future->setProgressValue(1);

View File

@@ -439,8 +439,8 @@ void ServerModeReader::handleReply(const QVariantMap &data, const QString &inRep
void ServerModeReader::handleError(const QString &message)
{
TaskHub::addTask(Task::Error, message, ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM,
Utils::FilePath(), -1);
TaskHub::addTask(BuildSystemTask(Task::Error, message));
if (!m_delayedErrorMessage.isEmpty()) {
reportError();
return;