forked from qt-creator/qt-creator
Meson: Reuse ProcessRunData instead of self-made Command struct
Change-Id: Ie4a989976e3684b0931d5cdb49fbc06b76ebcb67 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -65,7 +65,7 @@ class QTCREATOR_UTILS_EXPORT ProcessRunData
|
||||
public:
|
||||
Utils::CommandLine command;
|
||||
Utils::FilePath workingDirectory;
|
||||
Utils::Environment environment;
|
||||
Utils::Environment environment = {};
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT ProcessSetupData
|
||||
|
||||
@@ -121,11 +121,12 @@ bool MesonProjectParser::configure(const FilePath &sourcePath,
|
||||
m_buildDir = buildPath;
|
||||
m_outputParser.setSourceDirectory(sourcePath);
|
||||
auto cmd = MesonTools::toolById(m_meson, ToolType::Meson)->configure(sourcePath, buildPath, args);
|
||||
cmd.environment = m_env;
|
||||
// see comment near m_pendingCommands declaration
|
||||
m_pendingCommands.enqueue(
|
||||
std::make_tuple(MesonTools::toolById(m_meson, ToolType::Meson)->regenerate(sourcePath, buildPath),
|
||||
false));
|
||||
return run(cmd, m_env, m_projectName);
|
||||
auto enqCmd = MesonTools::toolById(m_meson, ToolType::Meson)->regenerate(sourcePath, buildPath);
|
||||
enqCmd.environment = m_env;
|
||||
m_pendingCommands.enqueue(std::make_tuple(enqCmd, false));
|
||||
return run(cmd, m_projectName);
|
||||
}
|
||||
|
||||
bool MesonProjectParser::wipe(const FilePath &sourcePath,
|
||||
@@ -148,7 +149,8 @@ bool MesonProjectParser::setup(const FilePath &sourcePath,
|
||||
if (forceWipe || isSetup(buildPath))
|
||||
cmdArgs << "--wipe";
|
||||
auto cmd = MesonTools::toolById(m_meson, ToolType::Meson)->setup(sourcePath, buildPath, cmdArgs);
|
||||
return run(cmd, m_env, m_projectName);
|
||||
cmd.environment = m_env;
|
||||
return run(cmd, m_projectName);
|
||||
}
|
||||
|
||||
bool MesonProjectParser::parse(const FilePath &sourcePath, const FilePath &buildPath)
|
||||
@@ -169,10 +171,9 @@ bool MesonProjectParser::parse(const FilePath &sourcePath)
|
||||
m_srcDir = sourcePath;
|
||||
m_introType = IntroDataType::stdo;
|
||||
m_outputParser.setSourceDirectory(sourcePath);
|
||||
return run(MesonTools::toolById(m_meson, ToolType::Meson)->introspect(sourcePath),
|
||||
m_env,
|
||||
m_projectName,
|
||||
true);
|
||||
auto cmd = MesonTools::toolById(m_meson, ToolType::Meson)->introspect(sourcePath);
|
||||
cmd.environment = m_env;
|
||||
return run(cmd, m_projectName, true);
|
||||
}
|
||||
|
||||
QList<BuildTargetInfo> MesonProjectParser::appsTargets() const
|
||||
@@ -324,19 +325,17 @@ bool MesonProjectParser::usesSameMesonVersion(const FilePath &buildPath)
|
||||
return !version.isNull() && meson && version == meson->version();
|
||||
}
|
||||
|
||||
bool MesonProjectParser::run(const Command &command,
|
||||
const Environment &env,
|
||||
const QString &projectName,
|
||||
bool MesonProjectParser::run(const ProcessRunData &runData, const QString &projectName,
|
||||
bool captureStdo)
|
||||
{
|
||||
if (!sanityCheck(command))
|
||||
if (!sanityCheck(runData))
|
||||
return false;
|
||||
m_stdo.clear();
|
||||
TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
|
||||
setupProcess(command, env, projectName, captureStdo);
|
||||
setupProcess(runData, projectName, captureStdo);
|
||||
m_elapsed.start();
|
||||
m_process->start();
|
||||
qCDebug(mesonProcessLog()) << "Starting:" << command.cmdLine.toUserOutput();
|
||||
qCDebug(mesonProcessLog()) << "Starting:" << runData.command.toUserOutput();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -351,12 +350,12 @@ void MesonProjectParser::handleProcessDone()
|
||||
MessageManager::writeSilently(elapsedTime);
|
||||
|
||||
if (m_process->exitCode() == 0 && m_process->exitStatus() == QProcess::NormalExit) {
|
||||
if (m_pendingCommands.isEmpty())
|
||||
if (m_pendingCommands.isEmpty()) {
|
||||
startParser();
|
||||
else {
|
||||
} 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));
|
||||
std::tuple<ProcessRunData, bool> args = m_pendingCommands.dequeue();
|
||||
run(std::get<0>(args), m_projectName, std::get<1>(args));
|
||||
}
|
||||
} else {
|
||||
if (m_introType == IntroDataType::stdo) {
|
||||
@@ -367,8 +366,8 @@ void MesonProjectParser::handleProcessDone()
|
||||
}
|
||||
}
|
||||
|
||||
void MesonProjectParser::setupProcess(const Command &command, const Environment &env,
|
||||
const QString &projectName, bool captureStdo)
|
||||
void MesonProjectParser::setupProcess(const ProcessRunData &runData, const QString &projectName,
|
||||
bool captureStdo)
|
||||
{
|
||||
if (m_process)
|
||||
m_process.release()->deleteLater();
|
||||
@@ -381,18 +380,16 @@ void MesonProjectParser::setupProcess(const Command &command, const Environment
|
||||
this, &MesonProjectParser::processStandardError);
|
||||
}
|
||||
|
||||
m_process->setWorkingDirectory(command.workDir);
|
||||
m_process->setEnvironment(env);
|
||||
MessageManager::writeFlashing(Tr::tr("Running %1 in %2.")
|
||||
.arg(command.cmdLine.toUserOutput(), command.workDir.toUserOutput()));
|
||||
m_process->setCommand(command.cmdLine);
|
||||
.arg(runData.command.toUserOutput(), runData.workingDirectory.toUserOutput()));
|
||||
m_process->setRunData(runData);
|
||||
ProcessProgress *progress = new ProcessProgress(m_process.get());
|
||||
progress->setDisplayName(Tr::tr("Configuring \"%1\".").arg(projectName));
|
||||
}
|
||||
|
||||
bool MesonProjectParser::sanityCheck(const Command &command) const
|
||||
bool MesonProjectParser::sanityCheck(const ProcessRunData &runData) const
|
||||
{
|
||||
const auto &exe = command.cmdLine.executable();
|
||||
const auto &exe = runData.command.executable();
|
||||
if (!exe.exists()) {
|
||||
//Should only reach this point if Meson exe is removed while a Meson project is opened
|
||||
TaskHub::addTask(
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <projectexplorer/kit.h>
|
||||
#include <projectexplorer/rawprojectpart.h>
|
||||
|
||||
#include <utils/processinterface.h>
|
||||
|
||||
#include <QFuture>
|
||||
#include <QQueue>
|
||||
|
||||
@@ -98,15 +100,14 @@ private:
|
||||
QString m_projectName;
|
||||
// maybe moving meson to build step could make this class simpler
|
||||
// also this should ease command dependencies
|
||||
QQueue<std::tuple<Command, bool>> m_pendingCommands;
|
||||
QQueue<std::tuple<Utils::ProcessRunData, bool>> m_pendingCommands;
|
||||
|
||||
bool run(const Command &command, const Utils::Environment &env,
|
||||
const QString &projectName, bool captureStdo = false);
|
||||
bool run(const Utils::ProcessRunData &runData, const QString &projectName, bool captureStdo = false);
|
||||
|
||||
void handleProcessDone();
|
||||
void setupProcess(const Command &command, const Utils::Environment &env,
|
||||
const QString &projectName, bool captureStdo);
|
||||
bool sanityCheck(const Command &command) const;
|
||||
void setupProcess(const Utils::ProcessRunData &runData, const QString &projectName,
|
||||
bool captureStdo);
|
||||
bool sanityCheck(const Utils::ProcessRunData &runData) const;
|
||||
|
||||
void processStandardOutput();
|
||||
void processStandardError();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/processinterface.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
@@ -123,17 +124,17 @@ QStringList options_cat(const T &...args)
|
||||
return result;
|
||||
}
|
||||
|
||||
Command ToolWrapper::setup(const FilePath &sourceDirectory,
|
||||
const FilePath &buildDirectory,
|
||||
const QStringList &options) const
|
||||
ProcessRunData ToolWrapper::setup(const FilePath &sourceDirectory,
|
||||
const FilePath &buildDirectory,
|
||||
const QStringList &options) const
|
||||
{
|
||||
return {{m_exe, options_cat("setup", options, sourceDirectory.path(), buildDirectory.path())},
|
||||
sourceDirectory};
|
||||
}
|
||||
|
||||
Command ToolWrapper::configure(const FilePath &sourceDirectory,
|
||||
const FilePath &buildDirectory,
|
||||
const QStringList &options) const
|
||||
ProcessRunData ToolWrapper::configure(const FilePath &sourceDirectory,
|
||||
const FilePath &buildDirectory,
|
||||
const QStringList &options) const
|
||||
{
|
||||
if (!isSetup(buildDirectory))
|
||||
return setup(sourceDirectory, buildDirectory, options);
|
||||
@@ -141,8 +142,8 @@ Command ToolWrapper::configure(const FilePath &sourceDirectory,
|
||||
buildDirectory};
|
||||
}
|
||||
|
||||
Command ToolWrapper::regenerate(const FilePath &sourceDirectory,
|
||||
const FilePath &buildDirectory) const
|
||||
ProcessRunData ToolWrapper::regenerate(const FilePath &sourceDirectory,
|
||||
const FilePath &buildDirectory) const
|
||||
{
|
||||
return {{m_exe,
|
||||
options_cat("--internal",
|
||||
@@ -154,7 +155,7 @@ Command ToolWrapper::regenerate(const FilePath &sourceDirectory,
|
||||
buildDirectory};
|
||||
}
|
||||
|
||||
Command ToolWrapper::introspect(const FilePath &sourceDirectory) const
|
||||
ProcessRunData ToolWrapper::introspect(const FilePath &sourceDirectory) const
|
||||
{
|
||||
return {{m_exe,
|
||||
{"introspect", "--all", QString("%1/meson.build").arg(sourceDirectory.path())}},
|
||||
@@ -173,11 +174,10 @@ bool containsFiles(const QString &path, const File_t &file, const T &...files)
|
||||
return containsFiles(path, file) && containsFiles(path, files...);
|
||||
}
|
||||
|
||||
bool run_meson(const Command &command, QIODevice *output)
|
||||
bool run_meson(const ProcessRunData &runData, QIODevice *output)
|
||||
{
|
||||
Process process;
|
||||
process.setWorkingDirectory(command.workDir);
|
||||
process.setCommand(command.cmdLine);
|
||||
process.setRunData(runData);
|
||||
process.start();
|
||||
if (!process.waitForFinished())
|
||||
return false;
|
||||
|
||||
@@ -12,17 +12,12 @@
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
|
||||
namespace Utils { class ProcessRunData; }
|
||||
|
||||
namespace MesonProjectManager::Internal {
|
||||
|
||||
enum class ToolType { Meson, Ninja };
|
||||
|
||||
class Command
|
||||
{
|
||||
public:
|
||||
Utils::CommandLine cmdLine;
|
||||
Utils::FilePath workDir;
|
||||
};
|
||||
|
||||
class ToolWrapper final
|
||||
{
|
||||
public:
|
||||
@@ -57,15 +52,15 @@ public:
|
||||
ToolType toolType() const { return m_toolType; }
|
||||
void setToolType(ToolType newToolType) { m_toolType = newToolType; }
|
||||
|
||||
Command setup(const Utils::FilePath &sourceDirectory,
|
||||
const Utils::FilePath &buildDirectory,
|
||||
const QStringList &options = {}) const;
|
||||
Command configure(const Utils::FilePath &sourceDirectory,
|
||||
const Utils::FilePath &buildDirectory,
|
||||
const QStringList &options = {}) const;
|
||||
Command regenerate(const Utils::FilePath &sourceDirectory,
|
||||
const Utils::FilePath &buildDirectory) const;
|
||||
Command introspect(const Utils::FilePath &sourceDirectory) const;
|
||||
Utils::ProcessRunData setup(const Utils::FilePath &sourceDirectory,
|
||||
const Utils::FilePath &buildDirectory,
|
||||
const QStringList &options = {}) const;
|
||||
Utils::ProcessRunData configure(const Utils::FilePath &sourceDirectory,
|
||||
const Utils::FilePath &buildDirectory,
|
||||
const QStringList &options = {}) const;
|
||||
Utils::ProcessRunData regenerate(const Utils::FilePath &sourceDirectory,
|
||||
const Utils::FilePath &buildDirectory) const;
|
||||
Utils::ProcessRunData introspect(const Utils::FilePath &sourceDirectory) const;
|
||||
|
||||
private:
|
||||
ToolType m_toolType;
|
||||
@@ -77,7 +72,7 @@ private:
|
||||
QString m_name;
|
||||
};
|
||||
|
||||
bool run_meson(const Command &command, QIODevice *output = nullptr);
|
||||
bool run_meson(const Utils::ProcessRunData &runData, QIODevice *output = nullptr);
|
||||
|
||||
bool isSetup(const Utils::FilePath &buildPath);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "mesontools.h"
|
||||
|
||||
#include <utils/launcherinterface.h>
|
||||
#include <utils/processinterface.h>
|
||||
#include <utils/singleton.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../mesontools.h"
|
||||
|
||||
#include <utils/launcherinterface.h>
|
||||
#include <utils/processinterface.h>
|
||||
#include <utils/singleton.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user