diff options
author | hjk <hjk@qt.io> | 2023-09-27 18:31:52 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2023-09-28 07:03:57 +0000 |
commit | 7bf1b6e586e8e56a1923419f58672772e575d7a6 (patch) | |
tree | 57a68af2de98e9d47cc8bf19910e9356bfd1b421 /src/plugins/mesonprojectmanager | |
parent | 895f8e73961d82a2a7971087df9248584eaa4eb0 (diff) |
Meson: De-noise project parser a bit
Change-Id: Ic0b19e5a1e10057f750c2ad13f61c09f1105d05d
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Diffstat (limited to 'src/plugins/mesonprojectmanager')
-rw-r--r-- | src/plugins/mesonprojectmanager/mesonprojectparser.cpp | 131 | ||||
-rw-r--r-- | src/plugins/mesonprojectmanager/mesonprojectparser.h | 37 |
2 files changed, 76 insertions, 92 deletions
diff --git a/src/plugins/mesonprojectmanager/mesonprojectparser.cpp b/src/plugins/mesonprojectmanager/mesonprojectparser.cpp index a4ac7a13252..5fb39a5f845 100644 --- a/src/plugins/mesonprojectmanager/mesonprojectparser.cpp +++ b/src/plugins/mesonprojectmanager/mesonprojectparser.cpp @@ -38,7 +38,7 @@ struct CompilerArgs { QStringList args; QStringList includePaths; - ProjectExplorer::Macros macros; + Macros macros; }; static std::optional<QString> extractValueIfMatches(const QString &arg, @@ -56,18 +56,18 @@ static std::optional<QString> extractInclude(const QString &arg) return extractValueIfMatches(arg, {"-I", "/I", "-isystem", "-imsvc", "/imsvc"}); } -static std::optional<ProjectExplorer::Macro> extractMacro(const QString &arg) +static std::optional<Macro> extractMacro(const QString &arg) { auto define = extractValueIfMatches(arg, {"-D", "/D"}); if (define) - return ProjectExplorer::Macro::fromKeyValue(define->toLatin1()); + return Macro::fromKeyValue(define->toLatin1()); auto undef = extractValueIfMatches(arg, {"-U", "/U"}); if (undef) - return ProjectExplorer::Macro(undef->toLatin1(), ProjectExplorer::MacroType::Undefine); + return Macro(undef->toLatin1(), MacroType::Undefine); return std::nullopt; } -CompilerArgs splitArgs(const QStringList &args) +static CompilerArgs splitArgs(const QStringList &args) { CompilerArgs splited; for (const QString &arg : args) { @@ -86,7 +86,7 @@ CompilerArgs splitArgs(const QStringList &args) return splited; } -QStringList toAbsolutePath(const Utils::FilePath &refPath, QStringList &pathList) +static QStringList toAbsolutePath(const FilePath &refPath, QStringList &pathList) { QStringList allAbs; std::transform(std::cbegin(pathList), @@ -98,9 +98,7 @@ QStringList toAbsolutePath(const Utils::FilePath &refPath, QStringList &pathList return allAbs; } -MesonProjectParser::MesonProjectParser(const Utils::Id &meson, - Utils::Environment env, - ProjectExplorer::Project *project) +MesonProjectParser::MesonProjectParser(const Id &meson, const Environment &env, Project *project) : m_env{env} , m_meson{meson} , m_projectName{project->displayName()} @@ -108,19 +106,14 @@ MesonProjectParser::MesonProjectParser(const Utils::Id &meson, // TODO re-think the way all BuildSystem/ProjectParser are tied // I take project info here, I also take build and src dir later from // functions args. - auto fileFinder = new Utils::FileInProjectFinder; + auto fileFinder = new FileInProjectFinder; fileFinder->setProjectDirectory(project->projectDirectory()); fileFinder->setProjectFiles(project->files(Project::AllFiles)); m_outputParser.setFileFinder(fileFinder); } -void MesonProjectParser::setMesonTool(const Utils::Id &meson) -{ - m_meson = meson; -} - -bool MesonProjectParser::configure(const Utils::FilePath &sourcePath, - const Utils::FilePath &buildPath, +bool MesonProjectParser::configure(const FilePath &sourcePath, + const FilePath &buildPath, const QStringList &args) { m_introType = IntroDataType::file; @@ -135,15 +128,15 @@ bool MesonProjectParser::configure(const Utils::FilePath &sourcePath, return run(cmd, m_env, m_projectName); } -bool MesonProjectParser::wipe(const Utils::FilePath &sourcePath, - const Utils::FilePath &buildPath, +bool MesonProjectParser::wipe(const FilePath &sourcePath, + const FilePath &buildPath, const QStringList &args) { return setup(sourcePath, buildPath, args, true); } -bool MesonProjectParser::setup(const Utils::FilePath &sourcePath, - const Utils::FilePath &buildPath, +bool MesonProjectParser::setup(const FilePath &sourcePath, + const FilePath &buildPath, const QStringList &args, bool forceWipe) { @@ -158,7 +151,7 @@ bool MesonProjectParser::setup(const Utils::FilePath &sourcePath, return run(cmd, m_env, m_projectName); } -bool MesonProjectParser::parse(const Utils::FilePath &sourcePath, const Utils::FilePath &buildPath) +bool MesonProjectParser::parse(const FilePath &sourcePath, const FilePath &buildPath) { m_srcDir = sourcePath; m_buildDir = buildPath; @@ -171,7 +164,7 @@ bool MesonProjectParser::parse(const Utils::FilePath &sourcePath, const Utils::F } } -bool MesonProjectParser::parse(const Utils::FilePath &sourcePath) +bool MesonProjectParser::parse(const FilePath &sourcePath) { m_srcDir = sourcePath; m_introType = IntroDataType::stdo; @@ -191,9 +184,9 @@ QList<BuildTargetInfo> MesonProjectParser::appsTargets() const bti.displayName = target.name; bti.buildKey = Target::fullName(m_buildDir, target); bti.displayNameUniquifier = bti.buildKey; - bti.targetFilePath = Utils::FilePath::fromString(target.fileName.first()); - bti.workingDirectory = Utils::FilePath::fromString(target.fileName.first()).absolutePath(); - bti.projectFilePath = Utils::FilePath::fromString(target.definedIn); + bti.targetFilePath = FilePath::fromString(target.fileName.first()); + bti.workingDirectory = FilePath::fromString(target.fileName.first()).absolutePath(); + bti.projectFilePath = FilePath::fromString(target.definedIn); bti.usesTerminal = true; apps.append(bti); } @@ -218,7 +211,7 @@ bool MesonProjectParser::startParser() } MesonProjectParser::ParserData *MesonProjectParser::extractParserResults( - const Utils::FilePath &srcDir, MesonInfoParser::Result &&parserResult) + const FilePath &srcDir, MesonInfoParser::Result &&parserResult) { auto rootNode = ProjectTree::buildTree(srcDir, parserResult.targets, @@ -226,13 +219,20 @@ MesonProjectParser::ParserData *MesonProjectParser::extractParserResults( return new ParserData{std::move(parserResult), std::move(rootNode)}; } -void MesonProjectParser::addMissingTargets(QStringList &targetList) +static void addMissingTargets(QStringList &targetList) { // Not all targets are listed in introspection data - for (const auto &target : additionalTargets()) { - if (!targetList.contains(target)) { + static const QString additionalTargets[] { + Constants::Targets::all, + Constants::Targets::clean, + Constants::Targets::install, + Constants::Targets::benchmark, + Constants::Targets::scan_build + }; + + for (const QString &target : additionalTargets) { + if (!targetList.contains(target)) targetList.append(target); - } } } @@ -261,7 +261,7 @@ RawProjectPart MesonProjectParser::buildRawPart( part.setDisplayName(target.name); part.setBuildSystemTarget(Target::fullName(m_buildDir, target)); part.setFiles(sources.sources + sources.generatedSources); - auto flags = splitArgs(sources.parameters); + CompilerArgs flags = splitArgs(sources.parameters); part.setMacros(flags.macros); part.setIncludePaths(toAbsolutePath(m_buildDir, flags.includePaths)); part.setProjectFileLocation(target.definedIn); @@ -273,29 +273,10 @@ RawProjectPart MesonProjectParser::buildRawPart( return part; } -void MesonProjectParser::processFinished(int exitCode, QProcess::ExitStatus exitStatus) -{ - if (exitCode == 0 && exitStatus == QProcess::NormalExit) { - if (m_pendingCommands.isEmpty()) - startParser(); - else { - // see comment near m_pendingCommands declaration - std::tuple<Command, bool> args = m_pendingCommands.dequeue(); - run(std::get<0>(args), m_env, m_projectName, std::get<1>(args)); - } - } else { - if (m_introType == IntroDataType::stdo) { - Core::MessageManager::writeSilently(QString::fromLocal8Bit(m_stderr)); - m_outputParser.readStdo(m_stderr); - } - emit parsingCompleted(false); - } -} - -ProjectExplorer::RawProjectParts MesonProjectParser::buildProjectParts( - const ProjectExplorer::ToolChain *cxxToolChain, const ProjectExplorer::ToolChain *cToolChain) +RawProjectParts MesonProjectParser::buildProjectParts( + const ToolChain *cxxToolChain, const ToolChain *cToolChain) { - ProjectExplorer::RawProjectParts parts; + RawProjectParts parts; for_each_source_group(m_parserResult.targets, [&parts, &cxxToolChain, @@ -326,7 +307,7 @@ bool MesonProjectParser::matchesKit(const KitData &kit) return matches; } -bool MesonProjectParser::usesSameMesonVersion(const Utils::FilePath &buildPath) +bool MesonProjectParser::usesSameMesonVersion(const FilePath &buildPath) { auto info = MesonInfoParser::mesonInfo(buildPath); auto meson = MesonTools::mesonWrapper(m_meson); @@ -342,7 +323,7 @@ bool MesonProjectParser::run(const Command &command, if (!sanityCheck(command)) return false; m_stdo.clear(); - ProjectExplorer::TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM); + TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM); setupProcess(command, env, projectName, captureStdo); m_elapsed.start(); m_process->start(); @@ -352,15 +333,29 @@ bool MesonProjectParser::run(const Command &command, void MesonProjectParser::handleProcessDone() { - if (m_process->result() != ProcessResult::FinishedWithSuccess) { - ProjectExplorer::TaskHub::addTask(ProjectExplorer::BuildSystemTask{ - ProjectExplorer::Task::TaskType::Error, m_process->exitMessage()}); - } + if (m_process->result() != ProcessResult::FinishedWithSuccess) + TaskHub::addTask(BuildSystemTask{Task::TaskType::Error, m_process->exitMessage()}); + m_stdo = m_process->readAllRawStandardOutput(); m_stderr = m_process->readAllRawStandardError(); const QString elapsedTime = formatElapsedTime(m_elapsed.elapsed()); MessageManager::writeSilently(elapsedTime); - processFinished(m_process->exitCode(), m_process->exitStatus()); + + if (m_process->exitCode() == 0 && m_process->exitStatus() == QProcess::NormalExit) { + if (m_pendingCommands.isEmpty()) + startParser(); + else { + // see comment near m_pendingCommands declaration + std::tuple<Command, bool> args = m_pendingCommands.dequeue(); + run(std::get<0>(args), m_env, m_projectName, std::get<1>(args)); + } + } else { + if (m_introType == IntroDataType::stdo) { + MessageManager::writeSilently(QString::fromLocal8Bit(m_stderr)); + m_outputParser.readStdo(m_stderr); + } + emit parsingCompleted(false); + } } void MesonProjectParser::setupProcess(const Command &command, const Environment &env, @@ -392,17 +387,15 @@ bool MesonProjectParser::sanityCheck(const Command &command) const const auto &exe = command.cmdLine().executable(); if (!exe.exists()) { //Should only reach this point if Meson exe is removed while a Meson project is opened - ProjectExplorer::TaskHub::addTask( - ProjectExplorer::BuildSystemTask{ProjectExplorer::Task::TaskType::Error, - Tr::tr("Executable does not exist: %1") - .arg(exe.toUserOutput())}); + TaskHub::addTask( + BuildSystemTask{Task::TaskType::Error, + Tr::tr("Executable does not exist: %1").arg(exe.toUserOutput())}); return false; } if (!exe.toFileInfo().isExecutable()) { - ProjectExplorer::TaskHub::addTask( - ProjectExplorer::BuildSystemTask{ProjectExplorer::Task::TaskType::Error, - Tr::tr("Command is not executable: %1") - .arg(exe.toUserOutput())}); + TaskHub::addTask( + BuildSystemTask{Task::TaskType::Error, + Tr::tr("Command is not executable: %1").arg(exe.toUserOutput())}); return false; } return true; diff --git a/src/plugins/mesonprojectmanager/mesonprojectparser.h b/src/plugins/mesonprojectmanager/mesonprojectparser.h index 3a129d60af1..a027aaa4d03 100644 --- a/src/plugins/mesonprojectmanager/mesonprojectparser.h +++ b/src/plugins/mesonprojectmanager/mesonprojectparser.h @@ -13,9 +13,6 @@ #include <projectexplorer/kit.h> #include <projectexplorer/rawprojectpart.h> -#include <utils/environment.h> -#include <utils/fileutils.h> - #include <QFuture> #include <QQueue> @@ -25,6 +22,7 @@ namespace Internal { class MesonProjectParser : public QObject { Q_OBJECT + enum class IntroDataType { file, stdo }; struct ParserData { @@ -33,8 +31,10 @@ class MesonProjectParser : public QObject }; public: - MesonProjectParser(const Utils::Id &meson, Utils::Environment env, ProjectExplorer::Project* project); - void setMesonTool(const Utils::Id &meson); + MesonProjectParser(const Utils::Id &meson, + const Utils::Environment &env, + ProjectExplorer::Project *project); + bool configure(const Utils::FilePath &sourcePath, const Utils::FilePath &buildPath, const QStringList &args); @@ -48,22 +48,11 @@ public: bool parse(const Utils::FilePath &sourcePath, const Utils::FilePath &buildPath); bool parse(const Utils::FilePath &sourcePath); - Q_SIGNAL void parsingCompleted(bool success); - std::unique_ptr<MesonProjectNode> takeProjectNode() { return std::move(m_rootNode); } - inline const BuildOptionsList &buildOptions() const { return m_parserResult.buildOptions; }; - inline const TargetsList &targets() const { return m_parserResult.targets; } - inline const QStringList &targetsNames() const { return m_targetsNames; } - - static inline QStringList additionalTargets() - { - return QStringList{Constants::Targets::all, - Constants::Targets::clean, - Constants::Targets::install, - Constants::Targets::benchmark, - Constants::Targets::scan_build}; - } + const BuildOptionsList &buildOptions() const { return m_parserResult.buildOptions; }; + const TargetsList &targets() const { return m_parserResult.targets; } + const QStringList &targetsNames() const { return m_targetsNames; } QList<ProjectExplorer::BuildTargetInfo> appsTargets() const; @@ -71,25 +60,27 @@ public: const ProjectExplorer::ToolChain *cxxToolChain, const ProjectExplorer::ToolChain *cToolChain); - inline void setEnvironment(const Utils::Environment &environment) { m_env = environment; } + void setEnvironment(const Utils::Environment &environment) { m_env = environment; } - inline void setQtVersion(Utils::QtMajorVersion v) { m_qtVersion = v; } + void setQtVersion(Utils::QtMajorVersion v) { m_qtVersion = v; } bool matchesKit(const KitData &kit); bool usesSameMesonVersion(const Utils::FilePath &buildPath); +signals: + void parsingCompleted(bool success); + private: bool startParser(); static ParserData *extractParserResults(const Utils::FilePath &srcDir, MesonInfoParser::Result &&parserResult); - static void addMissingTargets(QStringList &targetList); void update(const QFuture<ParserData *> &data); ProjectExplorer::RawProjectPart buildRawPart(const Target &target, const Target::SourceGroup &sources, const ProjectExplorer::ToolChain *cxxToolChain, const ProjectExplorer::ToolChain *cToolChain); - void processFinished(int exitCode, QProcess::ExitStatus exitStatus); + MesonOutputParser m_outputParser; Utils::Environment m_env; Utils::Id m_meson; |