diff --git a/kdevplatform/interfaces/iruntime.h b/kdevplatform/interfaces/iruntime.h --- a/kdevplatform/interfaces/iruntime.h +++ b/kdevplatform/interfaces/iruntime.h @@ -75,6 +75,13 @@ */ virtual Path pathInHost(const Path& runtimePath) const = 0; + /** + * Analogous to QStandardPaths::findExecutable(), searches for the executable + * named @p executableName in the runtime system paths. + * @returns the absolute file path to the executable, or an empty string if not found. + */ + virtual QString findExecutable(const QString& executableName) const = 0; + /** * @returns the value for an environment variable in the runtime */ diff --git a/kdevplatform/shell/runtimecontroller.cpp b/kdevplatform/shell/runtimecontroller.cpp --- a/kdevplatform/shell/runtimecontroller.cpp +++ b/kdevplatform/shell/runtimecontroller.cpp @@ -52,6 +52,10 @@ } KDevelop::Path pathInHost(const KDevelop::Path & runtimePath) const override { return runtimePath; } KDevelop::Path pathInRuntime(const KDevelop::Path & localPath) const override { return localPath; } + QString findExecutable(const QString& executableName) const override + { + return QStandardPaths::findExecutable(executableName); + } void setEnabled(bool /*enabled*/) override {} QByteArray getenv(const QByteArray & varname) const override { return qgetenv(varname.constData()); } KDevelop::Path buildPath() const override { return {}; } diff --git a/plugins/android/androidruntime.h b/plugins/android/androidruntime.h --- a/plugins/android/androidruntime.h +++ b/plugins/android/androidruntime.h @@ -41,6 +41,7 @@ KDevelop::Path pathInHost(const KDevelop::Path & runtimePath) const override { return runtimePath; } KDevelop::Path pathInRuntime(const KDevelop::Path & localPath) const override { return localPath; } QByteArray getenv(const QByteArray &varname) const override; + QString findExecutable(const QString& executableName) const override; KDevelop::Path buildPath() const override { return {}; } static AndroidPreferencesSettings* s_settings; diff --git a/plugins/android/androidruntime.cpp b/plugins/android/androidruntime.cpp --- a/plugins/android/androidruntime.cpp +++ b/plugins/android/androidruntime.cpp @@ -89,3 +89,16 @@ { return qgetenv(varname.constData()); } + +QString AndroidRuntime::findExecutable(const QString& executableName) const +{ + QStringList rtPaths; + + auto envPaths = getenv(QByteArrayLiteral("PATH")).split(':'); + std::transform(envPaths.begin(), envPaths.end(), std::back_inserter(rtPaths), + [this](QByteArray p) { + return pathInHost(Path(QString::fromLocal8Bit(p))).toLocalFile(); + }); + + return QStandardPaths::findExecutable(executableName, rtPaths); +} diff --git a/plugins/custom-definesandincludes/compilerprovider/compilerprovider.cpp b/plugins/custom-definesandincludes/compilerprovider/compilerprovider.cpp --- a/plugins/custom-definesandincludes/compilerprovider/compilerprovider.cpp +++ b/plugins/custom-definesandincludes/compilerprovider/compilerprovider.cpp @@ -261,15 +261,10 @@ return m_defaultProvider; auto rt = ICore::self()->runtimeController()->currentRuntime(); - const auto path = QFile::decodeName(rt->getenv("PATH")).split(QDir::listSeparator()); for ( const CompilerPointer& compiler : m_compilers ) { - const bool absolutePath = QDir::isAbsolutePath(compiler->path()); - if ((absolutePath && QFileInfo::exists(rt->pathInHost(Path(compiler->path())).toLocalFile())) - || QStandardPaths::findExecutable( compiler->path(), path).isEmpty() ) { + if (rt->findExecutable(compiler->path()).isEmpty()) continue; - } - m_defaultProvider = compiler; break; } diff --git a/plugins/docker/dockerruntime.h b/plugins/docker/dockerruntime.h --- a/plugins/docker/dockerruntime.h +++ b/plugins/docker/dockerruntime.h @@ -71,6 +71,8 @@ */ KDevelop::Path pathInRuntime(const KDevelop::Path & localPath) const override; + QString findExecutable(const QString& executableName) const override; + /** * @returns the environment variable with @p varname set by the recipe (usually the Dockerfile) */ diff --git a/plugins/docker/dockerruntime.cpp b/plugins/docker/dockerruntime.cpp --- a/plugins/docker/dockerruntime.cpp +++ b/plugins/docker/dockerruntime.cpp @@ -249,3 +249,15 @@ return localPath; } +QString DockerRuntime::findExecutable(const QString& executableName) const +{ + QStringList rtPaths; + + auto envPaths = getenv(QByteArrayLiteral("PATH")).split(':'); + std::transform(envPaths.begin(), envPaths.end(), std::back_inserter(rtPaths), + [this](QByteArray p) { + return pathInHost(Path(QString::fromLocal8Bit(p))).toLocalFile(); + }); + + return QStandardPaths::findExecutable(executableName, rtPaths); +} diff --git a/plugins/flatpak/flatpakruntime.h b/plugins/flatpak/flatpakruntime.h --- a/plugins/flatpak/flatpakruntime.h +++ b/plugins/flatpak/flatpakruntime.h @@ -40,6 +40,7 @@ void startProcess(QProcess *process) const override; KDevelop::Path pathInHost(const KDevelop::Path & runtimePath) const override; KDevelop::Path pathInRuntime(const KDevelop::Path & localPath) const override; + QString findExecutable(const QString& executableName) const override; QByteArray getenv(const QByteArray &varname) const override; static KJob* createBuildDirectory(const KDevelop::Path &path, const KDevelop::Path &file, const QString &arch); diff --git a/plugins/flatpak/flatpakruntime.cpp b/plugins/flatpak/flatpakruntime.cpp --- a/plugins/flatpak/flatpakruntime.cpp +++ b/plugins/flatpak/flatpakruntime.cpp @@ -230,6 +230,19 @@ return ret; } +QString FlatpakRuntime::findExecutable(const QString& executableName) const +{ + QStringList rtPaths; + + auto envPaths = getenv(QByteArrayLiteral("PATH")).split(':'); + std::transform(envPaths.begin(), envPaths.end(), std::back_inserter(rtPaths), + [this](QByteArray p) { + return pathInHost(Path(QString::fromLocal8Bit(p))).toLocalFile(); + }); + + return QStandardPaths::findExecutable(executableName, rtPaths); +} + QByteArray FlatpakRuntime::getenv(const QByteArray& varname) const { if (varname == "KDEV_DEFAULT_INSTALL_PREFIX")