Commit d1b13f52 authored by Gleb Popov's avatar Gleb Popov 💬

Add IRuntime::findExecutable method. Use it in `custom-definesandincludes`...

Add IRuntime::findExecutable method. Use it in `custom-definesandincludes` plugin when adding compilers.

Differential Revision: D5447
parent a96cb977
Pipeline #8259 passed with stage
in 51 minutes and 58 seconds
......@@ -75,6 +75,13 @@ public:
*/
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
*/
......
......@@ -52,6 +52,10 @@ public:
}
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 {}; }
......
......@@ -89,3 +89,16 @@ QByteArray AndroidRuntime::getenv(const QByteArray &varname) const
{
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);
}
......@@ -41,6 +41,7 @@ public:
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;
......
......@@ -261,15 +261,10 @@ CompilerPointer CompilerProvider::defaultCompiler() const
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;
}
......
......@@ -249,3 +249,15 @@ KDevelop::Path DockerRuntime::pathInRuntime(const KDevelop::Path& localPath) con
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);
}
......@@ -71,6 +71,8 @@ public:
*/
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)
*/
......
......@@ -230,6 +230,19 @@ Path FlatpakRuntime::pathInRuntime(const KDevelop::Path& localPath) const
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")
......
......@@ -40,6 +40,7 @@ public:
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);
......
Markdown is supported
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