Rework warning on invalid compiler
MODIFY
src/ccmanager.cpp
src/ccmanager.cpp
@@ -14,6 +14,31 @@ const static std::vector<QString> s_validAutodetectedCCs = {"riscv64-unknown-elf
"riscv64-unknown-elf-c++"};
const static QString s_testprogram = "int main() { return 0; }";
+QString indentString(const QString& string, int indent) {
+ auto subStrings = string.split("\n");
+ auto indentedStrings = QStringList();
+ for (const auto& str : qAsConst(subStrings)) {
+ indentedStrings << QString(" ").repeated(indent) + str;
+ }
+ return indentedStrings.join("\n");
+}
+
+QString CCManager::CompileError::toString(const CompileCommand& cc) const {
+ QStringList out;
+ auto indentAdd = [&](const QString& msg, const QString& indentMsg) {
+ if (!indentMsg.isEmpty()) {
+ out << msg;
+ out << indentString(indentMsg, 4);
+ }
+ };
+
+ indentAdd("Compilation failed", errMsg);
+ indentAdd("Compile command was:", cc.toString());
+ indentAdd("\nstdout output:", _stdout);
+ indentAdd("\nstderr output:", _stderr);
+ return out.join("\n");
+}
+
CCManager::CCManager() {
if (RipesSettings::value(RIPES_SETTING_CCPATH) == "") {
// No previous compiler path has been set. Try to autodetect a valid compiler within the current path
@@ -105,6 +130,7 @@ CCManager::CCRes CCManager::compile(const QStringList& files, QString outname, b
res.outFile = outname;
const auto cc = createCompileCommand(files, outname);
+ res.cc = cc;
// Run compiler
@@ -142,7 +168,6 @@ CCManager::CCRes CCManager::compile(const QStringList& files, QString outname, b
const bool success = LoadDialog::validateELFFile(QFile(outname)).valid;
res.success = success;
res.aborted = m_aborted;
- res.compileCommand = cc.toString();
return res;
}
@@ -163,7 +188,7 @@ QStringList sanitizedArguments(const QString& args) {
} // namespace
-CCManager::CC CCManager::createCompileCommand(const QStringList& files, const QString& outname) const {
+CCManager::CompileCommand CCManager::createCompileCommand(const QStringList& files, const QString& outname) const {
const auto& currentISA = ProcessorHandler::currentISA();
/**
@@ -179,7 +204,7 @@ CCManager::CC CCManager::createCompileCommand(const QStringList& files, const QS
* - %7: user linker arguments
*/
QStringList compileCommand;
- CC cc;
+ CompileCommand cc;
// Compiler path
cc.bin = QFileInfo(m_currentCC);
@@ -214,13 +239,13 @@ CCManager::CCRes CCManager::verifyCC(const QString& CCPath) {
const auto compilerExecInfo = QFileInfo(m_currentCC);
if (m_currentCC.isEmpty()) {
- res.errorMessage = "No path specified";
+ res.errorOutput.errMsg = "No path specified";
res.success = false;
goto verifyCC_end;
}
if (!compilerExecInfo.isExecutable()) {
- res.errorMessage = "'" + m_currentCC + "' is not an executable file.";
+ res.errorOutput.errMsg = "'" + m_currentCC + "' is not an executable file.";
res.success = false;
goto verifyCC_end;
}
@@ -228,12 +253,8 @@ CCManager::CCRes CCManager::verifyCC(const QString& CCPath) {
res = compileRaw(s_testprogram, QString(), false);
if (!res.success) {
- res.errorMessage += "Failed to compile test program.\n";
- res.errorMessage += "Compile command was: \n";
- res.errorMessage += "\t" + res.compileCommand + "\n";
- res.errorMessage += "Compiler output:\n";
- res.errorMessage += "\tstdout: " + QString(m_process.readAllStandardOutput()) + "\n";
- res.errorMessage += "\tstderr: " + QString(m_process.readAllStandardError()) + "\n";
+ res.errorOutput._stdout = QString(m_process.readAllStandardOutput());
+ res.errorOutput._stderr = QString(m_process.readAllStandardError());
}
// Cleanup

MODIFY
src/ccmanager.h
src/ccmanager.h
@@ -17,17 +17,23 @@ namespace Ripes {
class CCManager : public QObject {
Q_OBJECT
public:
- struct CC {
+ struct CompileCommand {
QFileInfo bin;
QStringList args;
- QString toString() const { return bin.absoluteFilePath() + " " + args.join(" "); }
+ QString toString() const { return (QStringList(bin.absoluteFilePath()) + args).join(" "); }
+ };
+ struct CompileError {
+ QString errMsg;
+ QString _stdout;
+ QString _stderr;
+ QString toString(const CompileCommand& cc) const;
};
struct CCRes {
QStringList inFiles;
QString outFile;
- QString errorMessage;
- QString compileCommand;
+ CompileError errorOutput;
+ CompileCommand cc;
bool success = false;
bool aborted = false;
@@ -54,7 +60,7 @@ public:
CCRes compile(const QTextDocument* source, QString outname = QString(), bool showProgressdiag = true);
CCRes compileRaw(const QString& rawsource, QString outname = QString(), bool showProgressdiag = true);
- CC createCompileCommand(const QStringList& files, const QString& outname) const;
+ CompileCommand createCompileCommand(const QStringList& files, const QString& outname) const;
signals:
/**

MODIFY
src/settingsdialog.cpp
src/settingsdialog.cpp
@@ -209,10 +209,9 @@ QWidget* SettingsDialog::createCompilerPage() {
f.setBold(true);
m_compileInfoHeader->setFont(f);
CCCLineHLayout->addWidget(m_compileInfoHeader);
- m_compileInfo = new QLabel();
- m_compileInfo->setWordWrap(true);
- m_compileInfo->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
- m_compileInfo->setTextInteractionFlags(Qt::TextSelectableByMouse);
+ m_compileInfo = new QPlainTextEdit();
+ m_compileInfo->setReadOnly(true);
+ m_compileInfo->setWordWrapMode(QTextOption::WordWrap);
CCCLineHLayout->addWidget(m_compileInfo);
CCLayout->addLayout(CCCLineHLayout);
@@ -253,12 +252,12 @@ void SettingsDialog::CCPathChanged(CCManager::CCRes res) {
m_ccpath->setPalette(palette);
// Update compile command preview
- auto [cstring, cargs] = CCManager::get().createCompileCommand({"${input}"}, "${output}");
+ auto cc = CCManager::get().createCompileCommand({"${input}"}, "${output}");
if (m_compileInfo) {
if (res.success) {
- m_compileInfo->setText(cstring + " " + cargs.join(" "));
+ m_compileInfo->setPlainText(cc.toString());
} else {
- m_compileInfo->setText(res.errorMessage);
+ m_compileInfo->setPlainText(res.errorOutput.toString(res.cc));
}
}
}

MODIFY
src/settingsdialog.h
src/settingsdialog.h
#pragma once
#include <QDialog>
+#include <QPlainTextEdit>
+
#include "ccmanager.h"
QT_FORWARD_DECLARE_CLASS(QLineEdit);
@@ -30,7 +32,7 @@ private:
*/
void CCPathChanged(CCManager::CCRes res);
QLineEdit* m_ccpath = nullptr;
- QLabel* m_compileInfo = nullptr;
+ QPlainTextEdit* m_compileInfo = nullptr;
QLabel* m_compileInfoHeader = nullptr;
QWidget* createCompilerPage();

Rework warning on invalid compiler