Commit d55325e7 authored by Harald Sitter's avatar Harald Sitter 🏳️‍🌈
Browse files

use startHostProcess when we intend a process to run on the host

parent 348d4880
Pipeline #200041 passed with stage
in 9 minutes and 26 seconds
add_library(cmaketoolsplugin MODULE "")
target_compile_definitions(cmaketoolsplugin PRIVATE TRANSLATION_DOMAIN="cmaketoolsplugin")
target_link_libraries(cmaketoolsplugin PRIVATE KF5::I18n KF5::TextEditor)
target_link_libraries(cmaketoolsplugin PRIVATE kateprivate KF5::I18n KF5::TextEditor)
target_sources(
cmaketoolsplugin
......
......@@ -5,6 +5,8 @@
*/
#include "cmakecompletion.h"
#include "hostprocess.h"
#include <KTextEditor/Document>
#include <KTextEditor/View>
......@@ -19,14 +21,13 @@ struct CMakeComplData {
static QByteArray runCMake(const QString &arg)
{
// only use cmake from PATH
static const auto cmakeExecutable = QStandardPaths::findExecutable(QStringLiteral("cmake"));
static const auto cmakeExecutable = safeExecutableName(QStringLiteral("cmake"));
if (cmakeExecutable.isEmpty()) {
return {};
}
QProcess p;
p.start(cmakeExecutable, {arg});
startHostProcess(p, cmakeExecutable, {arg});
if (p.waitForStarted() && p.waitForFinished()) {
if (p.exitCode() == 0 && p.exitStatus() == QProcess::NormalExit) {
return p.readAllStandardOutput();
......
......@@ -24,7 +24,7 @@ std::optional<QString> getDotGitPath(const QString &repo)
if (!setupGitProcess(git, repo, {QStringLiteral("rev-parse"), QStringLiteral("--absolute-git-dir")})) {
return std::nullopt;
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
if (git.exitStatus() != QProcess::NormalExit || git.exitCode() != 0) {
return std::nullopt;
......
......@@ -17,5 +17,5 @@ add_executable(externaltools_test
../katetoolrunner.cpp
)
add_test(NAME plugin-externaltools_test COMMAND externaltools_test)
target_link_libraries(externaltools_test PRIVATE Qt::Test KF5::I18n KF5::ConfigCore KF5::CoreAddons KF5::TextEditor)
target_link_libraries(externaltools_test PRIVATE kateprivate Qt::Test KF5::I18n KF5::ConfigCore KF5::CoreAddons KF5::TextEditor)
ecm_mark_as_test(externaltools_test)
......@@ -6,6 +6,8 @@
*/
#include "kateexternaltool.h"
#include "hostprocess.h"
#include <KConfigGroup>
#include <KLocalizedString>
#include <QStandardPaths>
......@@ -124,7 +126,7 @@ QString toString(KateExternalTool::Trigger trigger)
bool KateExternalTool::checkExec() const
{
return !QStandardPaths::findExecutable(executable).isEmpty();
return safeExecutableName(executable).isEmpty();
}
bool KateExternalTool::matchesMimetype(const QString &mt) const
......
......@@ -7,6 +7,7 @@
#include "katetoolrunner.h"
#include "hostprocess.h"
#include "kateexternaltool.h"
#include <KLocalizedString>
......@@ -42,7 +43,7 @@ KateExternalTool *KateToolRunner::tool() const
void KateToolRunner::run()
{
// always only execute the tool from PATH
const auto fullExecutable = QStandardPaths::findExecutable(m_tool->executable);
const auto fullExecutable = safeExecutableName(m_tool->executable);
if (fullExecutable.isEmpty()) {
return;
}
......@@ -79,7 +80,7 @@ void KateToolRunner::run()
});
const QStringList args = KShell::splitArgs(m_tool->arguments);
m_process->start(fullExecutable, args);
startHostProcess(*m_process, fullExecutable, args);
}
void KateToolRunner::waitForFinished()
......
......@@ -11,6 +11,7 @@
#include "debugview.h"
#include "dap/entities.h"
#include "hostprocess.h"
#include <QFile>
#include <QFileInfo>
......@@ -86,7 +87,7 @@ void DebugView::runDebugger(const GDBTargetConf &conf, const QStringList &ioFifo
}
// only run debugger from PATH or the absolute executable path we specified
const auto fullExecutable = QFileInfo(m_targetConf.gdbCmd).isAbsolute() ? m_targetConf.gdbCmd : QStandardPaths::findExecutable(m_targetConf.gdbCmd);
const auto fullExecutable = QFileInfo(m_targetConf.gdbCmd).isAbsolute() ? m_targetConf.gdbCmd : safeExecutableName(m_targetConf.gdbCmd);
if (fullExecutable.isEmpty()) {
return;
}
......@@ -111,7 +112,7 @@ void DebugView::runDebugger(const GDBTargetConf &conf, const QStringList &ioFifo
connect(&m_debugProcess, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &DebugView::slotDebugFinished);
m_debugProcess.start(fullExecutable, QStringList());
startHostProcess(m_debugProcess, fullExecutable);
m_nextCommands << QStringLiteral("set pagination off");
m_state = ready;
......
......@@ -266,7 +266,7 @@ static std::optional<QString> getGitCmdOutput(const QString &workDir, const QStr
if (!setupGitProcess(git, workDir, args)) {
return {};
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
if (git.exitStatus() != QProcess::NormalExit || git.exitCode() != 0) {
return std::nullopt;
......@@ -386,7 +386,7 @@ void CommitDiffTreeView::openCommit(const QString &hash, const QString &filePath
QByteArray numstat = contents.mid(firstNull + 1);
createFileTreeForCommit(filePath, numstat);
});
git->start();
startHostProcess(*git);
}
void CommitDiffTreeView::createFileTreeForCommit(const QString &filePath, const QByteArray &rawNumStat)
......@@ -448,7 +448,7 @@ void CommitDiffTreeView::showDiff(const QModelIndex &idx)
if (!setupGitProcess(git, m_gitDir, {QStringLiteral("show"), m_commitHash, QStringLiteral("--"), file})) {
return;
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
if (git.exitStatus() != QProcess::NormalExit || git.exitCode() != 0) {
......
......@@ -263,7 +263,7 @@ void KateGitBlamePluginView::startBlameProcess(const QUrl &url)
if (!setupGitProcess(m_blameInfoProc, fi.absolutePath(), {QStringLiteral("blame"), QStringLiteral("-p"), fi.absoluteFilePath()})) {
return;
}
m_blameInfoProc.start(QIODevice::ReadOnly);
startHostProcess(m_blameInfoProc, QIODevice::ReadOnly);
m_blameUrl = url;
}
......@@ -278,7 +278,7 @@ void KateGitBlamePluginView::startShowProcess(const QUrl &url, const QString &ha
if (!setupGitProcess(m_showProc, fi.absolutePath(), {QStringLiteral("show"), hash, QStringLiteral("--numstat")})) {
return;
}
m_showProc.start(QIODevice::ReadOnly);
startHostProcess(m_showProc, QIODevice::ReadOnly);
}
void KateGitBlamePluginView::showCommitInfo(const QString &hash, KTextEditor::View *view)
......
kate_add_plugin(katectagsplugin)
target_compile_definitions(katectagsplugin PRIVATE TRANSLATION_DOMAIN="kate-ctags-plugin")
target_link_libraries(katectagsplugin PRIVATE KF5::I18n KF5::TextEditor)
target_link_libraries(katectagsplugin PRIVATE kateprivate KF5::I18n KF5::TextEditor)
ki18n_wrap_ui(katectagsplugin kate_ctags.ui CTagsGlobalConfig.ui)
......
......@@ -5,6 +5,8 @@
*/
#include "gotosymbolmodel.h"
#include "hostprocess.h"
#include <KLocalizedString>
#include <QDebug>
#include <QProcess>
......@@ -60,7 +62,7 @@ void GotoSymbolModel::refresh(const QString &filePath)
endResetModel();
// only use ctags from PATH
static const auto fullExecutablePath = QStandardPaths::findExecutable(QStringLiteral("ctags"));
static const auto fullExecutablePath = safeExecutableName(QStringLiteral("ctags"));
if (fullExecutablePath.isEmpty()) {
beginResetModel();
m_rows.append(SymbolItem{i18n("CTags executable not found."), -1, QIcon()});
......@@ -69,7 +71,7 @@ void GotoSymbolModel::refresh(const QString &filePath)
}
QProcess p;
p.start(fullExecutablePath, {QStringLiteral("-x"), QStringLiteral("--_xformat=%{name}%{signature}\t%{kind}\t%{line}"), filePath});
startHostProcess(p, fullExecutablePath, {QStringLiteral("-x"), QStringLiteral("--_xformat=%{name}%{signature}\t%{kind}\t%{line}"), filePath});
QByteArray out;
if (p.waitForFinished()) {
......
......@@ -21,6 +21,8 @@
#include "kate_ctags_plugin.h"
#include "hostprocess.h"
#include <QCheckBox>
#include <QFileDialog>
#include <QFileInfo>
......@@ -225,7 +227,7 @@ void KateCTagsConfigPage::updateGlobalDB()
QString commandLine = QStringLiteral("%1 -f %2 %3").arg(m_confUi.cmdEdit->text(), file, targets);
QStringList arguments = m_proc.splitCommand(commandLine);
QString command = arguments.takeFirst();
m_proc.start(command, arguments);
startHostProcess(m_proc, command, arguments);
if (!m_proc.waitForStarted(500)) {
KMessageBox::error(nullptr, i18n("Failed to run \"%1\". exitStatus = %2", commandLine, m_proc.exitStatus()));
......
......@@ -24,6 +24,8 @@
#include "plugin_katebuild.h"
#include "hostprocess.h"
#include <cassert>
#include <QCompleter>
......@@ -807,7 +809,7 @@ bool KateBuildView::startProcess(const QString &dir, const QString &command)
m_proc.setProcessEnvironment(env);
m_proc.setWorkingDirectory(m_make_dir);
m_proc.setShellCommand(command);
m_proc.start();
startHostProcess(m_proc);
if (!m_proc.waitForStarted(500)) {
KMessageBox::error(nullptr, i18n("Failed to run \"%1\". exitStatus = %2", command, m_proc.exitStatus()));
......
......@@ -7,6 +7,7 @@
#include "lspclientserver.h"
#include "lspclient_debug.h"
#include "hostprocess.h"
#include <QCoreApplication>
#include <QFileInfo>
......@@ -1401,7 +1402,7 @@ public:
// we handle stdout/stderr internally, important stuff via stdout
m_sproc.setProcessChannelMode(forwardStdError ? QProcess::ForwardedErrorChannel : QProcess::SeparateChannels);
m_sproc.setReadChannel(QProcess::QProcess::StandardOutput);
m_sproc.start(program, args);
startHostProcess(m_sproc, program, args);
const bool result = m_sproc.waitForStarted();
if (result) {
setState(State::Started);
......
......@@ -10,6 +10,7 @@
#include "lspclientservermanager.h"
#include "hostprocess.h"
#include "lspclient_debug.h"
#include <KLocalizedString>
......@@ -724,7 +725,7 @@ private:
// ensure we always only take the server executable from the PATH or user defined paths
// QProcess will take the executable even just from current working directory without this => BAD
auto cmd = QStandardPaths::findExecutable(cmdline[0]);
auto cmd = safeExecutableName(cmdline[0]);
// optionally search in supplied path(s)
const auto vpath = serverConfig.value(QStringLiteral("path")).toArray();
......@@ -736,7 +737,7 @@ private:
editor->expandText(p, view, p);
path.push_back(p);
}
cmd = QStandardPaths::findExecutable(cmdline[0], path);
cmd = safeExecutableName(cmdline[0], path);
}
// we can only start the stuff if we did find the binary in the paths
......
add_executable(lsptestapp "")
target_include_directories(lsptestapp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..)
target_link_libraries(lsptestapp PRIVATE KF5::TextEditor)
target_link_libraries(lsptestapp PRIVATE kateprivate KF5::TextEditor)
target_sources(
lsptestapp
......
......@@ -161,7 +161,7 @@ void CompareBranchesView::showDiff(const QModelIndex &idx)
if (!setupGitProcess(git, m_gitDir, {QStringLiteral("diff"), QStringLiteral("%1...%2").arg(m_fromBr).arg(m_toBr), QStringLiteral("--"), file})) {
return;
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
if (git.exitStatus() != QProcess::NormalExit || git.exitCode() != 0) {
......
......@@ -251,7 +251,7 @@ void FileHistoryWidget::getFileHistory(const QString &file)
}
});
m_git.start(QProcess::ReadOnly);
startHostProcess(m_git, QProcess::ReadOnly);
}
void FileHistoryWidget::itemClicked(const QModelIndex &idx)
......@@ -265,7 +265,7 @@ void FileHistoryWidget::itemClicked(const QModelIndex &idx)
return;
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
if (git.exitStatus() != QProcess::NormalExit || git.exitCode() != 0) {
return;
......
......@@ -24,7 +24,7 @@ static void numStatForStatus(QVector<GitUtils::StatusItem> &list, const QString
if (!setupGitProcess(git, workDir, args)) {
return;
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
if (git.exitStatus() != QProcess::NormalExit || git.exitCode() != 0) {
return;
......
......@@ -19,7 +19,7 @@ bool GitUtils::isGitRepo(const QString &repo)
return false;
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
return git.readAll().trimmed() == "true";
}
......@@ -34,7 +34,7 @@ std::optional<QString> GitUtils::getDotGitPath(const QString &repo)
return std::nullopt;
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
if (git.exitStatus() != QProcess::NormalExit || git.exitCode() != 0) {
return std::nullopt;
......@@ -67,7 +67,7 @@ QString GitUtils::getCurrentBranchName(const QString &repo)
return QString();
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
if (git.exitStatus() == QProcess::NormalExit && git.exitCode() == 0) {
return QString::fromUtf8(git.readAllStandardOutput().trimmed());
......@@ -86,7 +86,7 @@ GitUtils::CheckoutResult GitUtils::checkoutBranch(const QString &repo, const QSt
return CheckoutResult{};
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
CheckoutResult res;
res.branch = branch;
if (git.waitForStarted() && git.waitForFinished(-1)) {
......@@ -108,7 +108,7 @@ GitUtils::CheckoutResult GitUtils::checkoutNewBranch(const QString &repo, const
return CheckoutResult{};
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
CheckoutResult res;
res.branch = newBranch;
if (git.waitForStarted() && git.waitForFinished(-1)) {
......@@ -152,7 +152,7 @@ QVector<GitUtils::Branch> GitUtils::getAllBranchesAndTags(const QString &repo, R
return {};
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
QVector<Branch> branches;
if (git.waitForStarted() && git.waitForFinished(-1)) {
QString gitout = QString::fromUtf8(git.readAllStandardOutput());
......@@ -191,7 +191,7 @@ QVector<GitUtils::Branch> GitUtils::getAllLocalBranchesWithLastCommitSubject(con
return {};
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
QVector<Branch> branches;
if (git.waitForStarted() && git.waitForFinished(-1)) {
QByteArray gitout = git.readAllStandardOutput();
......@@ -228,7 +228,7 @@ std::pair<QString, QString> GitUtils::getLastCommitMessage(const QString &repo)
return {};
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
if (git.exitCode() != 0 || git.exitStatus() != QProcess::NormalExit) {
return {};
......@@ -262,7 +262,7 @@ GitUtils::Result GitUtils::deleteBranches(const QStringList &branches, const QSt
return {};
}
git.start(QProcess::ReadOnly);
startHostProcess(git, QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
QString out = QString::fromLatin1(git.readAllStandardError()) + QString::fromLatin1(git.readAllStandardOutput());
return {out, git.exitCode()};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment