| 
									
										
										
										
											2022-08-19 15:59:36 +02:00
										 |  |  | // Copyright (C) 2020 Alexis Jeandet.
 | 
					
						
							| 
									
										
										
										
											2022-12-21 10:12:09 +01:00
										 |  |  | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
 | 
					
						
							| 
									
										
										
										
											2020-10-29 10:20:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-01 18:20:56 +02:00
										 |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2020-10-29 10:20:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "versionhelper.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-11 14:34:56 +02:00
										 |  |  | #include <utils/commandline.h>
 | 
					
						
							| 
									
										
										
										
											2020-05-01 18:20:56 +02:00
										 |  |  | #include <utils/environment.h>
 | 
					
						
							|  |  |  | #include <utils/fileutils.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-26 13:59:38 +02:00
										 |  |  | #include <utils/id.h>
 | 
					
						
							| 
									
										
										
										
											2020-05-01 18:20:56 +02:00
										 |  |  | #include <utils/qtcassert.h>
 | 
					
						
							| 
									
										
										
										
											2020-10-29 10:20:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-01 18:20:56 +02:00
										 |  |  | #include <QFileInfo>
 | 
					
						
							|  |  |  | #include <QUuid>
 | 
					
						
							|  |  |  | #include <QVariant>
 | 
					
						
							|  |  |  | #include <QVariantMap>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-26 10:30:00 +02:00
										 |  |  | #include <optional>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-01 18:20:56 +02:00
										 |  |  | namespace MesonProjectManager { | 
					
						
							|  |  |  | namespace Internal { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Command | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Utils::CommandLine m_cmd; | 
					
						
							|  |  |  |     Utils::FilePath m_workDir; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     Command() = default; | 
					
						
							|  |  |  |     Command(const Utils::FilePath &exe, const Utils::FilePath &workDir, const QStringList &args) | 
					
						
							|  |  |  |         : m_cmd{exe, args} | 
					
						
							|  |  |  |         , m_workDir{workDir} | 
					
						
							|  |  |  |     {} | 
					
						
							|  |  |  |     inline const Utils::CommandLine &cmdLine() const { return m_cmd; } | 
					
						
							|  |  |  |     inline const Utils::FilePath &workDir() const { return m_workDir; } | 
					
						
							|  |  |  |     inline Utils::FilePath executable() const { return m_cmd.executable(); } | 
					
						
							|  |  |  |     inline QStringList arguments() const { return m_cmd.splitArguments(); } | 
					
						
							|  |  |  |     inline QString toUserOutput() const { return m_cmd.toUserOutput(); }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ToolWrapper | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     virtual ~ToolWrapper(){}; | 
					
						
							|  |  |  |     ToolWrapper() = delete; | 
					
						
							|  |  |  |     ToolWrapper(const QString &name, const Utils::FilePath &path, bool autoDetected = false); | 
					
						
							|  |  |  |     ToolWrapper(const QString &name, | 
					
						
							|  |  |  |                 const Utils::FilePath &path, | 
					
						
							| 
									
										
										
										
											2020-06-26 13:59:38 +02:00
										 |  |  |                 const Utils::Id &id, | 
					
						
							| 
									
										
										
										
											2020-05-01 18:20:56 +02:00
										 |  |  |                 bool autoDetected = false); | 
					
						
							|  |  |  |     ToolWrapper(const ToolWrapper &other) = default; | 
					
						
							|  |  |  |     ToolWrapper(ToolWrapper &&other) = default; | 
					
						
							|  |  |  |     ToolWrapper &operator=(const ToolWrapper &other) = default; | 
					
						
							|  |  |  |     ToolWrapper &operator=(ToolWrapper &&other) = default; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     inline const Version &version() const noexcept { return m_version; }; | 
					
						
							|  |  |  |     inline bool isValid() const noexcept { return m_isValid; }; | 
					
						
							|  |  |  |     inline bool autoDetected() const noexcept { return m_autoDetected; }; | 
					
						
							| 
									
										
										
										
											2020-06-26 13:59:38 +02:00
										 |  |  |     inline Utils::Id id() const noexcept { return m_id; }; | 
					
						
							| 
									
										
										
										
											2020-05-01 18:20:56 +02:00
										 |  |  |     inline Utils::FilePath exe() const noexcept { return m_exe; }; | 
					
						
							|  |  |  |     inline QString name() const noexcept { return m_name; }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     inline void setName(const QString &newName) { m_name = newName; } | 
					
						
							|  |  |  |     virtual void setExe(const Utils::FilePath &newExe); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static Version read_version(const Utils::FilePath &toolPath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-26 10:30:00 +02:00
										 |  |  |     static std::optional<Utils::FilePath> findTool(const QStringList &exeNames); | 
					
						
							| 
									
										
										
										
											2020-05-01 18:20:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     template<typename T> | 
					
						
							|  |  |  |     friend QVariantMap toVariantMap(const T &); | 
					
						
							|  |  |  |     template<typename T> | 
					
						
							|  |  |  |     friend T fromVariantMap(const QVariantMap &); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     Version m_version; | 
					
						
							|  |  |  |     bool m_isValid; | 
					
						
							|  |  |  |     bool m_autoDetected; | 
					
						
							| 
									
										
										
										
											2020-06-26 13:59:38 +02:00
										 |  |  |     Utils::Id m_id; | 
					
						
							| 
									
										
										
										
											2020-05-01 18:20:56 +02:00
										 |  |  |     Utils::FilePath m_exe; | 
					
						
							|  |  |  |     QString m_name; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<typename T> | 
					
						
							|  |  |  | QVariantMap toVariantMap(const T &); | 
					
						
							|  |  |  | template<typename T> | 
					
						
							|  |  |  | T fromVariantMap(const QVariantMap &); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace Internal
 | 
					
						
							|  |  |  | } // namespace MesonProjectManager
 |