Make changes in compiler settings trigger compiler reverification
MODIFY
src/ccmanager.cpp
src/ccmanager.cpp
@@ -32,11 +32,16 @@ CCManager::CCManager() {
}
}
+ // At startup, we will always try to validate whether the current CC set in the settings is (still) valid.
if (RipesSettings::value(RIPES_SETTING_CCPATH) != "") {
- verifyCC(RipesSettings::value(RIPES_SETTING_CCPATH).toString());
+ trySetCC(RipesSettings::value(RIPES_SETTING_CCPATH).toString());
}
}
+bool CCManager::hasValidCC() const {
+ return !m_currentCC.isEmpty();
+}
+
QString CCManager::tryAutodetectCC() {
for (const auto& path : s_validAutodetectedCCs) {
QProcess process;
@@ -53,7 +58,18 @@ QString CCManager::tryAutodetectCC() {
return QString();
}
-void CCManager::verifyCC(const QString& CCPath) {
+bool CCManager::trySetCC(const QString& CC) {
+ const bool success = verifyCC(CC);
+ if (success) {
+ m_currentCC = CC;
+ } else {
+ m_currentCC = QString();
+ }
+ emit ccChanged(success);
+ return success;
+}
+
+bool CCManager::verifyCC(const QString& CCPath) {
// Write test program to temporary file with a .c extension
QTemporaryFile testSrcFile(QDir::tempPath() + QDir::separator() + QCoreApplication::applicationName() +
@@ -87,19 +103,22 @@ void CCManager::verifyCC(const QString& CCPath) {
process.start(s_cc);
process.waitForFinished();
- if (!QFile::exists(testSrcFileOut)) {
+ const bool success = QFile::exists(testSrcFileOut);
+
#ifdef QT_DEBUG
+ if (!success) {
qDebug() << "Failed to compile test program";
qDebug() << "CC output: ";
qDebug() << "Standard output: " << process.readAllStandardOutput();
qDebug() << "Standard error: " << process.readAllStandardError();
-#endif
- } else {
}
+#endif
// Cleanup
QFile::remove(testSrcFile.fileName());
QFile::remove(testSrcFileOut);
+
+ return success;
}
} // namespace Ripes

MODIFY
src/ccmanager.h
src/ccmanager.h
#pragma once
+#include <QObject>
#include <QString>
namespace Ripes {
@@ -9,13 +10,32 @@ namespace Ripes {
* Manages the detection, verification and execution of a valid C/C++ compiler suitable for the ISAs targetted by the
* various processor models of Ripes.
*/
-class CCManager {
+class CCManager : public QObject {
+ Q_OBJECT
public:
static CCManager& get() {
static CCManager manager;
return manager;
}
+ bool hasValidCC() const;
+ const QString& currentCC() const { return m_currentCC; }
+
+signals:
+ /**
+ * @brief ccChanged
+ * Emitted whenever the current CC path changed. @param valid indicates whether the CC was successfully validated.
+ */
+ void ccChanged(bool valid);
+
+public slots:
+ /**
+ * @brief trySetCC
+ * Attempts to set the path @param CC to be the current compiler.
+ * @return true if the CC was successfully validated and set
+ */
+ bool trySetCC(const QString& CC);
+
private:
/**
* @brief tryAutodetectCC
@@ -25,11 +45,14 @@ private:
/**
* @brief verifyCC
- * Attempts to compile a simple test program using the provided compiler path @param CC
+ * Attempts to compile a simple test program using the provided compiler path @param CC.
+ * @returns true if successful.
*/
- void verifyCC(const QString& CC);
+ bool verifyCC(const QString& CC);
CCManager();
+
+ QString m_currentCC;
};
} // namespace Ripes

MODIFY
src/settingsdialog.cpp
src/settingsdialog.cpp
#include "ccmanager.h"
#include "ripessettings.h"
+#include <QFileDialog>
#include <QGroupBox>
#include <QLabel>
#include <QLayout>
@@ -88,10 +89,29 @@ QWidget* SettingsDialog::createEditorPage() {
auto* CCHLayout = new QHBoxLayout();
auto [cclabel, ccpath] = createSettingsWidgets<QLineEdit>(RIPES_SETTING_CCPATH, "C/C++ compiler path:");
+ m_ccpath = ccpath;
CCLayout->addLayout(CCHLayout);
CCHLayout->addWidget(cclabel);
CCHLayout->addWidget(ccpath);
auto* pathBrowseButton = new QPushButton("Browse");
+ connect(pathBrowseButton, &QPushButton::clicked, [=, ccpath = ccpath] {
+ QFileDialog dialog(this);
+ dialog.setAcceptMode(QFileDialog::AcceptOpen);
+ if (dialog.exec()) {
+ ccpath->setText(dialog.selectedFiles()[0]);
+ }
+ });
+
+ // Make changes in the CC path trigger revalidation in the CCManager
+ connect(ccpath, &QLineEdit::textChanged, &CCManager::get(), &CCManager::trySetCC);
+
+ // Make CCManager compiler changes trigger background color of the ccpath, indicating whether the CC was determined
+ // to be valid
+ connect(&CCManager::get(), &CCManager::ccChanged, this, &SettingsDialog::CCPathChanged);
+
+ // Trigger initial rehighlighting
+ CCManager::get().trySetCC(CCManager::get().currentCC());
+
CCHLayout->addWidget(pathBrowseButton);
pageLayout->addWidget(CCGroupBox);
@@ -99,6 +119,16 @@ QWidget* SettingsDialog::createEditorPage() {
return pageWidget;
}
+void SettingsDialog::CCPathChanged(bool valid) {
+ QPalette palette = this->palette();
+ if (!valid) {
+ palette.setColor(QPalette::Base, QColor(Qt::red).lighter());
+ } else {
+ palette.setColor(QPalette::Base, QColor(Qt::green).lighter());
+ }
+ m_ccpath->setPalette(palette);
+}
+
QWidget* SettingsDialog::createSimulatorPage() {
auto [pageWidget, pageLayout] = constructPage();

MODIFY
src/settingsdialog.h
src/settingsdialog.h
#include <QDialog>
+QT_FORWARD_DECLARE_CLASS(QLineEdit);
+
namespace Ripes {
namespace Ui {
@@ -18,6 +20,13 @@ public:
void accept() override;
private:
+ /**
+ * @brief CCPathChanged
+ * Rehighlightss the current CCPath if the CC is @param valid
+ */
+ void CCPathChanged(bool valid);
+ QLineEdit* m_ccpath = nullptr;
+
QWidget* createEditorPage();
QWidget* createSimulatorPage();

Make changes in compiler settings trigger compiler reverification