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
|
|
|
#include "toolwrapper.h"
|
|
|
|
|
|
2024-02-27 16:08:45 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2021-08-31 11:50:19 +02:00
|
|
|
|
2020-05-01 18:20:56 +02:00
|
|
|
namespace MesonProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
ToolWrapper::ToolWrapper(const QString &name, const Utils::FilePath &path, bool autoDetected)
|
|
|
|
|
: m_version(read_version(path))
|
|
|
|
|
, m_isValid{path.exists() && m_version.isValid}
|
|
|
|
|
, m_autoDetected{autoDetected}
|
2024-07-12 11:32:14 +02:00
|
|
|
, m_id{Utils::Id::generate()}
|
2020-05-01 18:20:56 +02:00
|
|
|
, m_exe{path}
|
|
|
|
|
, m_name{name}
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
ToolWrapper::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)
|
|
|
|
|
: m_version(read_version(path))
|
|
|
|
|
, m_isValid{path.exists() && m_version.isValid}
|
|
|
|
|
, m_autoDetected{autoDetected}
|
|
|
|
|
, m_id{id}
|
|
|
|
|
, m_exe{path}
|
|
|
|
|
, m_name{name}
|
|
|
|
|
{
|
2024-07-12 11:32:14 +02:00
|
|
|
QTC_ASSERT(m_id.isValid(), m_id = Utils::Id::generate());
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolWrapper::setExe(const Utils::FilePath &newExe)
|
|
|
|
|
{
|
|
|
|
|
m_exe = newExe;
|
|
|
|
|
m_version = read_version(m_exe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Version ToolWrapper::read_version(const Utils::FilePath &toolPath)
|
|
|
|
|
{
|
|
|
|
|
if (toolPath.toFileInfo().isExecutable()) {
|
2023-05-03 16:00:22 +02:00
|
|
|
Utils::Process process;
|
2021-08-31 11:50:19 +02:00
|
|
|
process.setCommand({ toolPath, { "--version" } });
|
|
|
|
|
process.start();
|
|
|
|
|
if (process.waitForFinished())
|
2022-06-17 14:17:14 +02:00
|
|
|
return Version::fromString(process.cleanedStdOut());
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
std::optional<Utils::FilePath> ToolWrapper::findTool(const QStringList &exeNames)
|
2020-05-01 18:20:56 +02:00
|
|
|
{
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
Environment systemEnvironment = Environment::systemEnvironment();
|
|
|
|
|
for (const auto &exe : exeNames) {
|
|
|
|
|
const FilePath exe_path = systemEnvironment.searchInPath(exe);
|
|
|
|
|
if (exe_path.exists())
|
|
|
|
|
return exe_path;
|
|
|
|
|
}
|
2022-08-26 10:30:00 +02:00
|
|
|
return std::nullopt;
|
2020-05-01 18:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace MesonProjectManager
|