CMakePM: Allow usage of custom output parsers for CMake output

Fixes: QTCREATORBUG-29992
Change-Id: Ia84871cc963263c34054d17742556b38a1f1934e
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Cristian Adam
2023-12-06 15:41:02 +01:00
parent d5b3366d55
commit 6846579266
3 changed files with 31 additions and 1 deletions

View File

@@ -8,16 +8,19 @@
#include "cmakekitaspect.h" #include "cmakekitaspect.h"
#include "cmaketoolmanager.h" #include "cmaketoolmanager.h"
#include <projectexplorer/customparser.h>
#include <projectexplorer/kitaspects.h> #include <projectexplorer/kitaspects.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h> #include <projectexplorer/toolchain.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/aspects.h>
#include <utils/macroexpander.h> #include <utils/macroexpander.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils;
namespace CMakeProjectManager::Internal { namespace CMakeProjectManager::Internal {
@@ -70,6 +73,15 @@ BuildDirParameters::BuildDirParameters(CMakeBuildSystem *buildSystem)
environment.setFallback("CLICOLOR_FORCE", "1"); environment.setFallback("CLICOLOR_FORCE", "1");
cmakeToolId = CMakeKitAspect::cmakeToolId(k); cmakeToolId = CMakeKitAspect::cmakeToolId(k);
outputParserGenerator = [k, bc]() {
QList<OutputLineParser *> outputParsers = k->createOutputParsers();
for (const Id id : bc->customParsers()) {
if (auto parser = createCustomParserFromId(id))
outputParsers << parser;
}
return outputParsers;
};
} }
bool BuildDirParameters::isValid() const bool BuildDirParameters::isValid() const
@@ -82,4 +94,10 @@ CMakeTool *BuildDirParameters::cmakeTool() const
return CMakeToolManager::findById(cmakeToolId); return CMakeToolManager::findById(cmakeToolId);
} }
QList<OutputLineParser *> BuildDirParameters::outputParsers() const
{
QTC_ASSERT(outputParserGenerator, return {});
return outputParserGenerator();
}
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal

View File

@@ -8,7 +8,12 @@
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/filepath.h> #include <utils/filepath.h>
namespace Utils { class MacroExpander; } #include <functional>
namespace Utils {
class MacroExpander;
class OutputLineParser;
} // namespace Utils
namespace CMakeProjectManager::Internal { namespace CMakeProjectManager::Internal {
@@ -38,6 +43,12 @@ public:
QStringList additionalCMakeArguments; QStringList additionalCMakeArguments;
Utils::MacroExpander* expander = nullptr; Utils::MacroExpander* expander = nullptr;
QList<Utils::OutputLineParser*> outputParsers() const;
private:
using OutputParserGenerator = std::function<QList<Utils::OutputLineParser*>()>;
OutputParserGenerator outputParserGenerator;
}; };
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal

View File

@@ -110,6 +110,7 @@ void CMakeProcess::run(const BuildDirParameters &parameters, const QStringList &
const auto parser = new CMakeParser; const auto parser = new CMakeParser;
parser->setSourceDirectory(parameters.sourceDirectory); parser->setSourceDirectory(parameters.sourceDirectory);
m_parser.addLineParser(parser); m_parser.addLineParser(parser);
m_parser.addLineParsers(parameters.outputParsers());
// Always use the sourceDir: If we are triggered because the build directory is getting deleted // Always use the sourceDir: If we are triggered because the build directory is getting deleted
// then we are racing against CMakeCache.txt also getting deleted. // then we are racing against CMakeCache.txt also getting deleted.