File indexing completed on 2024-05-05 16:45:14
0001 // SPDX-FileCopyrightText: 2022 Gleb Popov <arrowd@FreeBSD.org> 0002 // SPDX-License-Identifier: BSD-3-Clause 0003 0004 #ifndef CRAFTRUNTIME_H 0005 #define CRAFTRUNTIME_H 0006 0007 #include <vector> 0008 0009 #include <QString> 0010 #include <QFileSystemWatcher> 0011 #include <interfaces/iruntime.h> 0012 #include <util/path.h> 0013 0014 class QProcess; 0015 0016 namespace KDevelop { 0017 class IProject; 0018 } 0019 0020 // An auxiliary structure to hold normalized name and value of an env var 0021 struct EnvironmentVariable 0022 { 0023 EnvironmentVariable(const QByteArray& name, const QByteArray& value); 0024 0025 QByteArray name; 0026 QByteArray value; 0027 }; 0028 Q_DECLARE_TYPEINFO(EnvironmentVariable, Q_MOVABLE_TYPE); 0029 0030 class CraftRuntime : public KDevelop::IRuntime 0031 { 0032 Q_OBJECT 0033 public: 0034 CraftRuntime(const QString& craftRoot, const QString& pythonExecutable); 0035 0036 QString name() const override; 0037 void setEnabled(bool enabled) override; 0038 void startProcess(KProcess* process) const override; 0039 void startProcess(QProcess* process) const override; 0040 KDevelop::Path pathInHost(const KDevelop::Path& runtimePath) const override; 0041 KDevelop::Path pathInRuntime(const KDevelop::Path& localPath) const override; 0042 QString findExecutable(const QString& executableName) const override; 0043 QByteArray getenv(const QByteArray& varname) const override; 0044 0045 KDevelop::Path buildPath() const override 0046 { 0047 return {}; 0048 } 0049 QString craftRoot() const 0050 { 0051 return m_craftRoot; 0052 } 0053 0054 static QString findCraftRoot(KDevelop::Path startingPoint); 0055 static QString findPython(); 0056 0057 private: 0058 void setEnvironmentVariables(QProcess* process) const; 0059 void refreshEnvCache(); 0060 0061 const QString m_craftRoot; 0062 const QString m_pythonExecutable; 0063 QFileSystemWatcher m_watcher; 0064 std::vector<EnvironmentVariable> m_envCache; 0065 }; 0066 0067 #endif // CRAFTRUNTIME_H