forked from qt-creator/qt-creator
Coco: Merge cocoinstallation.* into globalsettings.*
This is mechanical so far, the plan is to merge the class together with the GlobalSettings namespace into a CocoSettings class with the usual access pattern. Later the m_cocoPathAspect from GlobalSettingsWidget can be moved there and /probably/ be merged with CocoInstallationPrivate ::cocoPath. Change-Id: If156a5ea78335e30372414cb1583d8e68f4f90ba Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -17,8 +17,6 @@ add_qtc_plugin(Coco
|
||||
cococmakesettings.h
|
||||
cococommon.cpp
|
||||
cococommon.h
|
||||
cocoinstallation.cpp
|
||||
cocoinstallation.h
|
||||
cocolanguageclient.cpp
|
||||
cocolanguageclient.h
|
||||
cocoplugin.cpp
|
||||
|
@@ -23,8 +23,6 @@ QtcPlugin {
|
||||
"cococmakesettings.h",
|
||||
"cococommon.cpp",
|
||||
"cococommon.h",
|
||||
"cocoinstallation.cpp",
|
||||
"cocoinstallation.h",
|
||||
"cocolanguageclient.cpp",
|
||||
"cocolanguageclient.h",
|
||||
"cocoplugin.cpp",
|
||||
|
@@ -3,9 +3,9 @@
|
||||
|
||||
#include "cocobuildstep.h"
|
||||
|
||||
#include "cocoinstallation.h"
|
||||
#include "cocopluginconstants.h"
|
||||
#include "cocotr.h"
|
||||
#include "globalsettings.h"
|
||||
|
||||
#include <cmakeprojectmanager/cmakeprojectconstants.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
|
@@ -1,177 +0,0 @@
|
||||
// Copyright (C) 2024 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "cocoinstallation.h"
|
||||
|
||||
#include "cococommon.h"
|
||||
#include "cocotr.h"
|
||||
#include "globalsettings.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
#include <QProcess>
|
||||
#include <QStandardPaths>
|
||||
#include <QRegularExpression>
|
||||
|
||||
namespace Coco::Internal {
|
||||
|
||||
struct CocoInstallationPrivate
|
||||
{
|
||||
Utils::FilePath cocoPath;
|
||||
bool isValid = false;
|
||||
QString errorMessage = Tr::tr("Error: Coco installation directory not set. (This can't happen.)");
|
||||
};
|
||||
|
||||
CocoInstallationPrivate *CocoInstallation::d = nullptr;
|
||||
|
||||
CocoInstallation::CocoInstallation()
|
||||
{
|
||||
if (!d)
|
||||
d = new CocoInstallationPrivate;
|
||||
}
|
||||
|
||||
Utils::FilePath CocoInstallation::directory() const
|
||||
{
|
||||
return d->cocoPath;
|
||||
}
|
||||
|
||||
Utils::FilePath CocoInstallation::coverageBrowserPath() const
|
||||
{
|
||||
QString browserPath;
|
||||
|
||||
if (Utils::HostOsInfo::isAnyUnixHost() || Utils::HostOsInfo::isMacHost())
|
||||
browserPath = "bin/coveragebrowser";
|
||||
else
|
||||
browserPath = "coveragebrowser.exe";
|
||||
|
||||
return d->cocoPath.resolvePath(browserPath);
|
||||
}
|
||||
|
||||
void CocoInstallation::setDirectory(const Utils::FilePath &dir)
|
||||
{
|
||||
if (isCocoDirectory(dir)) {
|
||||
d->cocoPath = dir;
|
||||
d->isValid = true;
|
||||
d->errorMessage = "";
|
||||
verifyCocoDirectory();
|
||||
}
|
||||
else {
|
||||
d->cocoPath = Utils::FilePath();
|
||||
d->isValid = false;
|
||||
d->errorMessage
|
||||
= Tr::tr("Error: Coco installation directory not found at \"%1\".").arg(dir.nativePath());
|
||||
}
|
||||
}
|
||||
|
||||
Utils::FilePath CocoInstallation::coverageScannerPath(const Utils::FilePath &cocoDir) const
|
||||
{
|
||||
QString scannerPath;
|
||||
|
||||
if (Utils::HostOsInfo::isAnyUnixHost() || Utils::HostOsInfo::isMacHost())
|
||||
scannerPath = "bin/coveragescanner";
|
||||
else
|
||||
scannerPath = "coveragescanner.exe";
|
||||
|
||||
return cocoDir.resolvePath(scannerPath);
|
||||
}
|
||||
|
||||
bool CocoInstallation::isCocoDirectory(const Utils::FilePath &cocoDir) const
|
||||
{
|
||||
return coverageScannerPath(cocoDir).exists();
|
||||
}
|
||||
|
||||
void CocoInstallation::logError(const QString &msg)
|
||||
{
|
||||
logFlashing(msg);
|
||||
d->isValid = false;
|
||||
d->errorMessage = msg;
|
||||
}
|
||||
|
||||
bool CocoInstallation::verifyCocoDirectory()
|
||||
{
|
||||
QString coveragescanner = coverageScannerPath(d->cocoPath).nativePath();
|
||||
|
||||
QProcess proc;
|
||||
proc.setProgram(coveragescanner);
|
||||
proc.setArguments({"--cs-help"});
|
||||
proc.start();
|
||||
|
||||
if (!proc.waitForStarted()) {
|
||||
logError(Tr::tr("Error: Coveragescanner at \"%1\" did not start.").arg(coveragescanner));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!proc.waitForFinished()) {
|
||||
logError(Tr::tr("Error: Coveragescanner at \"%1\" did not finish.").arg(coveragescanner));
|
||||
return false;
|
||||
}
|
||||
|
||||
QString result = QString::fromLatin1(proc.readAll());
|
||||
static const QRegularExpression linebreak("\n|\r\n|\r");
|
||||
QStringList lines = result.split(linebreak, Qt::SkipEmptyParts);
|
||||
|
||||
const qsizetype n = lines.size();
|
||||
if (n >= 2 && lines[n - 2].startsWith("Version:") && lines[n - 1].startsWith("Date:")) {
|
||||
logSilently(Tr::tr("Valid CoverageScanner found at \"%1\":").arg(coveragescanner));
|
||||
logSilently(" " + lines[n - 2]);
|
||||
logSilently(" " + lines[n - 1]);
|
||||
return true;
|
||||
} else {
|
||||
logError(
|
||||
Tr::tr("Error: Coveragescanner at \"%1\" did not run correctly.").arg(coveragescanner));
|
||||
for (const QString &l : lines) {
|
||||
logSilently(l);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CocoInstallation::isValid() const
|
||||
{
|
||||
return d->isValid;
|
||||
}
|
||||
|
||||
QString CocoInstallation::errorMessage() const
|
||||
{
|
||||
return d->errorMessage;
|
||||
}
|
||||
|
||||
void CocoInstallation::tryPath(const QString &path)
|
||||
{
|
||||
if (d->isValid)
|
||||
return;
|
||||
|
||||
const auto fpath = Utils::FilePath::fromString(path);
|
||||
const QString nativePath = fpath.nativePath();
|
||||
if (isCocoDirectory(fpath)) {
|
||||
logSilently(Tr::tr("Found Coco directory \"%1\".").arg(nativePath));
|
||||
setDirectory(fpath);
|
||||
GlobalSettings::save();
|
||||
} else
|
||||
logSilently(Tr::tr("Checked Coco directory \"%1\".").arg(nativePath));
|
||||
}
|
||||
|
||||
QString CocoInstallation::envVar(const QString &var) const
|
||||
{
|
||||
return QProcessEnvironment::systemEnvironment().value(var);
|
||||
}
|
||||
|
||||
void CocoInstallation::findDefaultDirectory()
|
||||
{
|
||||
if (Utils::HostOsInfo::isMacHost())
|
||||
tryPath("/Applications/SquishCoco");
|
||||
else if (Utils::HostOsInfo::isAnyUnixHost()) {
|
||||
tryPath((Utils::FileUtils::homePath() / "SquishCoco").nativePath());
|
||||
tryPath("/opt/SquishCoco");
|
||||
} else {
|
||||
tryPath(envVar("SQUISHCOCO"));
|
||||
QStringList homeDirs = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
|
||||
if (!homeDirs.isEmpty())
|
||||
tryPath(homeDirs[0] + "/squishcoco");
|
||||
tryPath(envVar("ProgramFiles") + "\\squishcoco");
|
||||
tryPath(envVar("ProgramFiles(x86)") + "\\squishcoco");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Coco::Internal
|
||||
|
@@ -1,39 +0,0 @@
|
||||
// Copyright (C) 2024 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utils/filepath.h>
|
||||
|
||||
class QString;
|
||||
|
||||
namespace Coco::Internal {
|
||||
|
||||
struct CocoInstallationPrivate;
|
||||
|
||||
// Borg pattern: There are many instances of this class, but all are the same.
|
||||
class CocoInstallation
|
||||
{
|
||||
public:
|
||||
CocoInstallation();
|
||||
|
||||
Utils::FilePath directory() const;
|
||||
Utils::FilePath coverageBrowserPath() const;
|
||||
void setDirectory(const Utils::FilePath &dir);
|
||||
void findDefaultDirectory();
|
||||
|
||||
bool isValid() const;
|
||||
QString errorMessage() const;
|
||||
|
||||
private:
|
||||
Utils::FilePath coverageScannerPath(const Utils::FilePath &cocoDir) const;
|
||||
void logError(const QString &msg);
|
||||
bool isCocoDirectory(const Utils::FilePath &cocoDir) const;
|
||||
bool verifyCocoDirectory();
|
||||
void tryPath(const QString &path);
|
||||
QString envVar(const QString &var) const;
|
||||
|
||||
static CocoInstallationPrivate *d;
|
||||
};
|
||||
|
||||
} // namespace Coco::Internal
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "buildsettings.h"
|
||||
#include "cocoinstallation.h"
|
||||
#include "globalsettings.h"
|
||||
|
||||
#include <projectexplorer/buildconfiguration.h>
|
||||
#include <utils/aspects.h>
|
||||
|
@@ -5,10 +5,10 @@
|
||||
|
||||
#include "buildsettings.h"
|
||||
#include "cococommon.h"
|
||||
#include "cocoinstallation.h"
|
||||
#include "cocopluginconstants.h"
|
||||
#include "cocoprojectwidget.h"
|
||||
#include "cocotr.h"
|
||||
#include "globalsettings.h"
|
||||
#include "qmakefeaturefile.h"
|
||||
|
||||
#include <utils/commandline.h>
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "globalsettings.h"
|
||||
|
||||
#include "cocoinstallation.h"
|
||||
#include "cococommon.h"
|
||||
#include "cocopluginconstants.h"
|
||||
#include "cocotr.h"
|
||||
|
||||
@@ -11,10 +11,14 @@
|
||||
|
||||
#include <utils/fancylineedit.h>
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
|
||||
namespace Coco::Internal {
|
||||
namespace GlobalSettings {
|
||||
@@ -55,6 +59,163 @@ void save()
|
||||
|
||||
} // namespace GlobalSettings
|
||||
|
||||
struct CocoInstallationPrivate
|
||||
{
|
||||
Utils::FilePath cocoPath;
|
||||
bool isValid = false;
|
||||
QString errorMessage = Tr::tr("Error: Coco installation directory not set. (This can't happen.)");
|
||||
};
|
||||
|
||||
CocoInstallationPrivate *CocoInstallation::d = nullptr;
|
||||
|
||||
CocoInstallation::CocoInstallation()
|
||||
{
|
||||
if (!d)
|
||||
d = new CocoInstallationPrivate;
|
||||
}
|
||||
|
||||
Utils::FilePath CocoInstallation::directory() const
|
||||
{
|
||||
return d->cocoPath;
|
||||
}
|
||||
|
||||
Utils::FilePath CocoInstallation::coverageBrowserPath() const
|
||||
{
|
||||
QString browserPath;
|
||||
|
||||
if (Utils::HostOsInfo::isAnyUnixHost() || Utils::HostOsInfo::isMacHost())
|
||||
browserPath = "bin/coveragebrowser";
|
||||
else
|
||||
browserPath = "coveragebrowser.exe";
|
||||
|
||||
return d->cocoPath.resolvePath(browserPath);
|
||||
}
|
||||
|
||||
void CocoInstallation::setDirectory(const Utils::FilePath &dir)
|
||||
{
|
||||
if (isCocoDirectory(dir)) {
|
||||
d->cocoPath = dir;
|
||||
d->isValid = true;
|
||||
d->errorMessage = "";
|
||||
verifyCocoDirectory();
|
||||
}
|
||||
else {
|
||||
d->cocoPath = Utils::FilePath();
|
||||
d->isValid = false;
|
||||
d->errorMessage
|
||||
= Tr::tr("Error: Coco installation directory not found at \"%1\".").arg(dir.nativePath());
|
||||
}
|
||||
}
|
||||
|
||||
Utils::FilePath CocoInstallation::coverageScannerPath(const Utils::FilePath &cocoDir) const
|
||||
{
|
||||
QString scannerPath;
|
||||
|
||||
if (Utils::HostOsInfo::isAnyUnixHost() || Utils::HostOsInfo::isMacHost())
|
||||
scannerPath = "bin/coveragescanner";
|
||||
else
|
||||
scannerPath = "coveragescanner.exe";
|
||||
|
||||
return cocoDir.resolvePath(scannerPath);
|
||||
}
|
||||
|
||||
bool CocoInstallation::isCocoDirectory(const Utils::FilePath &cocoDir) const
|
||||
{
|
||||
return coverageScannerPath(cocoDir).exists();
|
||||
}
|
||||
|
||||
void CocoInstallation::logError(const QString &msg)
|
||||
{
|
||||
logFlashing(msg);
|
||||
d->isValid = false;
|
||||
d->errorMessage = msg;
|
||||
}
|
||||
|
||||
bool CocoInstallation::verifyCocoDirectory()
|
||||
{
|
||||
QString coveragescanner = coverageScannerPath(d->cocoPath).nativePath();
|
||||
|
||||
QProcess proc;
|
||||
proc.setProgram(coveragescanner);
|
||||
proc.setArguments({"--cs-help"});
|
||||
proc.start();
|
||||
|
||||
if (!proc.waitForStarted()) {
|
||||
logError(Tr::tr("Error: Coveragescanner at \"%1\" did not start.").arg(coveragescanner));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!proc.waitForFinished()) {
|
||||
logError(Tr::tr("Error: Coveragescanner at \"%1\" did not finish.").arg(coveragescanner));
|
||||
return false;
|
||||
}
|
||||
|
||||
QString result = QString::fromLatin1(proc.readAll());
|
||||
static const QRegularExpression linebreak("\n|\r\n|\r");
|
||||
QStringList lines = result.split(linebreak, Qt::SkipEmptyParts);
|
||||
|
||||
const qsizetype n = lines.size();
|
||||
if (n >= 2 && lines[n - 2].startsWith("Version:") && lines[n - 1].startsWith("Date:")) {
|
||||
logSilently(Tr::tr("Valid CoverageScanner found at \"%1\":").arg(coveragescanner));
|
||||
logSilently(" " + lines[n - 2]);
|
||||
logSilently(" " + lines[n - 1]);
|
||||
return true;
|
||||
} else {
|
||||
logError(
|
||||
Tr::tr("Error: Coveragescanner at \"%1\" did not run correctly.").arg(coveragescanner));
|
||||
for (const QString &l : lines) {
|
||||
logSilently(l);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CocoInstallation::isValid() const
|
||||
{
|
||||
return d->isValid;
|
||||
}
|
||||
|
||||
QString CocoInstallation::errorMessage() const
|
||||
{
|
||||
return d->errorMessage;
|
||||
}
|
||||
|
||||
void CocoInstallation::tryPath(const QString &path)
|
||||
{
|
||||
if (d->isValid)
|
||||
return;
|
||||
|
||||
const auto fpath = Utils::FilePath::fromString(path);
|
||||
const QString nativePath = fpath.nativePath();
|
||||
if (isCocoDirectory(fpath)) {
|
||||
logSilently(Tr::tr("Found Coco directory \"%1\".").arg(nativePath));
|
||||
setDirectory(fpath);
|
||||
GlobalSettings::save();
|
||||
} else
|
||||
logSilently(Tr::tr("Checked Coco directory \"%1\".").arg(nativePath));
|
||||
}
|
||||
|
||||
QString CocoInstallation::envVar(const QString &var) const
|
||||
{
|
||||
return QProcessEnvironment::systemEnvironment().value(var);
|
||||
}
|
||||
|
||||
void CocoInstallation::findDefaultDirectory()
|
||||
{
|
||||
if (Utils::HostOsInfo::isMacHost())
|
||||
tryPath("/Applications/SquishCoco");
|
||||
else if (Utils::HostOsInfo::isAnyUnixHost()) {
|
||||
tryPath((Utils::FileUtils::homePath() / "SquishCoco").nativePath());
|
||||
tryPath("/opt/SquishCoco");
|
||||
} else {
|
||||
tryPath(envVar("SQUISHCOCO"));
|
||||
QStringList homeDirs = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
|
||||
if (!homeDirs.isEmpty())
|
||||
tryPath(homeDirs[0] + "/squishcoco");
|
||||
tryPath(envVar("ProgramFiles") + "\\squishcoco");
|
||||
tryPath(envVar("ProgramFiles(x86)") + "\\squishcoco");
|
||||
}
|
||||
}
|
||||
GlobalSettingsWidget::GlobalSettingsWidget(QFrame *parent)
|
||||
: QFrame(parent)
|
||||
{
|
||||
|
@@ -3,8 +3,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cocoinstallation.h"
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
#include <QPointer>
|
||||
@@ -17,6 +15,32 @@ void save();
|
||||
|
||||
} // GlobalSettings
|
||||
|
||||
struct CocoInstallationPrivate;
|
||||
|
||||
// Borg pattern: There are many instances of this class, but all are the same.
|
||||
class CocoInstallation
|
||||
{
|
||||
public:
|
||||
CocoInstallation();
|
||||
|
||||
Utils::FilePath directory() const;
|
||||
Utils::FilePath coverageBrowserPath() const;
|
||||
void setDirectory(const Utils::FilePath &dir);
|
||||
void findDefaultDirectory();
|
||||
|
||||
bool isValid() const;
|
||||
QString errorMessage() const;
|
||||
|
||||
private:
|
||||
Utils::FilePath coverageScannerPath(const Utils::FilePath &cocoDir) const;
|
||||
void logError(const QString &msg);
|
||||
bool isCocoDirectory(const Utils::FilePath &cocoDir) const;
|
||||
bool verifyCocoDirectory();
|
||||
void tryPath(const QString &path);
|
||||
QString envVar(const QString &var) const;
|
||||
|
||||
static CocoInstallationPrivate *d;
|
||||
};
|
||||
|
||||
class GlobalSettingsWidget : public QFrame
|
||||
{
|
||||
|
Reference in New Issue
Block a user