Skip to content

Commit

Permalink
add support for using local -I / -D flags
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Dec 7, 2017
1 parent 2e8088a commit 5653f37
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 60 deletions.
5 changes: 3 additions & 2 deletions src/CompilerExplorer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"Description" : "Plugin based on https://github.com/mattgodbolt/compiler-explorer.",
"Url" : "https://github.com/dobokirisame",
"Dependencies" : [
{ "Name" : "Core", "Version" : "4.3.0" },
{ "Name" : "ProjectExplorer", "Version" : "4.3.0" }
{ "Name" : "Core", "Version" : "4.5.0" },
{ "Name" : "ProjectExplorer", "Version" : "4.5.0" },
{ "Name" : "CppTools", "Version" : "4.5.0" }
]
}
16 changes: 8 additions & 8 deletions src/CompilerExplorerPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ namespace compilerExplorer {
namespace core {

CompilerExplorerPlugin::CompilerExplorerPlugin()
: mOutputPane(nullptr),
mOptionsPage(nullptr),
mNodeJsServer(nullptr) {
: mOutputPane(nullptr),
mOptionsPage(nullptr),
mNodeJsServer(nullptr) {

}

Expand All @@ -45,7 +45,7 @@ bool CompilerExplorerPlugin::initialize(const QStringList &arguments, QString *e

auto action = new QAction(QIcon(":/images/run.png"), tr("Run Compiler Explorer"), this);
Core::Command *cmd = Core::ActionManager::registerAction(action, constants::ACTION_ID,
Core::Context(Core::Constants::C_GLOBAL));
Core::Context(Core::Constants::C_GLOBAL));
connect(action, &QAction::triggered, mOutputPane, &gui::ExplorerOutputPane::runCompilerExplorer);

Core::ActionContainer *menu = Core::ActionManager::createMenu(constants::MENU_ID);
Expand All @@ -59,9 +59,9 @@ bool CompilerExplorerPlugin::initialize(const QStringList &arguments, QString *e
ProjectExplorer::ProjectPanelFactory::registerFactory(mPanelFactory.get());
mOptionsPage = new gui::CompilerExplorerOptionsPage(this);
connect(mOptionsPage, &gui::CompilerExplorerOptionsPage::settingsChanged,
this, &CompilerExplorerPlugin::restartNodeJsServer);
this, &CompilerExplorerPlugin::restartNodeJsServer);
connect(this, &CompilerExplorerPlugin::serverChanged,
this, &CompilerExplorerPlugin::updateGui);
this, &CompilerExplorerPlugin::updateGui);
addAutoReleasedObject(mOptionsPage);
mNodeJsServer = new QProcess(this);
restartNodeJsServer();
Expand All @@ -79,7 +79,7 @@ void CompilerExplorerPlugin::restartNodeJsServer() {
const auto &settings = mOptionsPage->settings();
const auto nodeJsLocation = settings.value(constants::nodejsFileNameKey).toString();
const auto compilerExplorerLocation = settings.value(constants::compilerExplorerLocationKey,
QString()).toString();
QString()).toString();
const auto useLocalServer = settings.value(constants::useLocalServerKey).toBool();
const auto startLocalServer = settings.value(constants::startLocalServerKey).toBool();
const auto localPort = settings.value(constants::localServerPortKey, 10240).toInt();
Expand All @@ -99,7 +99,7 @@ void CompilerExplorerPlugin::restartNodeJsServer() {
}
QStringList args;
args << compilerExplorerLocation +"/app.js" << "--language C++"
<< "--port=" + QString::number(localPort);
<< "--port=" + QString::number(localPort);
mNodeJsServer->setWorkingDirectory(compilerExplorerLocation);
mNodeJsServer->start(nodeJsLocation + " " + args.join(" "));
emit serverChanged();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/CompilerExplorerOptionsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace compilerExplorer {
namespace gui{
CompilerExplorerOptionsPage::CompilerExplorerOptionsPage(QObject *parent)
: Core::IOptionsPage(parent),
mWidget(nullptr) {
: Core::IOptionsPage(parent),
mWidget(nullptr) {
setId("CompilerExplorerSettings");
setDisplayName(tr("Compiler Explorer"));
setCategory("Compiler Explorer");
Expand Down
24 changes: 12 additions & 12 deletions src/gui/CompilerExplorerOptionsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace compilerExplorer {
namespace gui{

CompilerExplorerOptionsWidget::CompilerExplorerOptionsWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::CompilerExplorerOptionsWidget) {
QWidget(parent),
ui(new Ui::CompilerExplorerOptionsWidget) {
ui->setupUi(this);
}

Expand All @@ -21,17 +21,17 @@ void CompilerExplorerOptionsWidget::loadSettings(const QSettings &settings) {
const auto nodejsLocation = settings.value(constants::nodejsFileNameKey, QString()).toString();
ui->nodejsLocation->setText(nodejsLocation);
const auto compilerExplorerLocation = settings.value(constants::compilerExplorerLocationKey,
QString()).toString();
QString()).toString();
ui->compilerExplorerLocation->setText(compilerExplorerLocation);
const auto useLocalServer = settings.value(constants::useLocalServerKey, true).toBool();
ui->useLocalServerButton->setChecked(useLocalServer);
ui->useRemoteServer->setChecked(!useLocalServer);
const auto localPort = settings.value(constants::localServerPortKey,
10240).toInt();
10240).toInt();
ui->localPort->setValue(localPort);
const auto startLocalServer = settings.value(constants::startLocalServerKey, true).toBool();
const auto remoteServerUrl = settings.value(constants::remoteServerUrlKey,
QString("https://gcc.godbolt.org/")).toString();
QString("https://gcc.godbolt.org/")).toString();
ui->remoteServerUrl->setText(remoteServerUrl);
ui->localServerGroupBox->setEnabled(useLocalServer);
ui->localServerSettingsGroup->setChecked(startLocalServer);
Expand All @@ -41,7 +41,7 @@ void CompilerExplorerOptionsWidget::loadSettings(const QSettings &settings) {
void CompilerExplorerOptionsWidget::apply(QSettings &settings) {
const auto nodejsLocation = settings.value(constants::nodejsFileNameKey, QString()).toString();
const auto compilerExplorerLocation = settings.value(constants::compilerExplorerLocationKey,
QString()).toString();
QString()).toString();
const auto useLocalServer = settings.value(constants::useLocalServerKey).toBool();
const auto startLocalServer = settings.value(constants::startLocalServerKey, true).toBool();
const auto remoteServerUrl = settings.value(constants::remoteServerUrlKey, QString()).toString();
Expand All @@ -55,18 +55,18 @@ void CompilerExplorerOptionsWidget::apply(QSettings &settings) {
settings.setValue(constants::remoteServerUrlKey, ui->remoteServerUrl->text());

if((nodejsLocation != ui->nodejsLocation->text()) ||
startLocalServer != ui->localServerSettingsGroup->isChecked() ||
compilerExplorerLocation != ui->compilerExplorerLocation->text() ||
useLocalServer != ui->useLocalServerButton->isChecked() ||
localPort != ui->localPort->value() ||
remoteServerUrl != ui->remoteServerUrl->text()) {
startLocalServer != ui->localServerSettingsGroup->isChecked() ||
compilerExplorerLocation != ui->compilerExplorerLocation->text() ||
useLocalServer != ui->useLocalServerButton->isChecked() ||
localPort != ui->localPort->value() ||
remoteServerUrl != ui->remoteServerUrl->text()) {
emit settingsChanged();
}
}

void CompilerExplorerOptionsWidget::on_toolButton_clicked() {
QString res = QFileDialog::getOpenFileName(this, tr("NodeJS"),
QString(), tr("node ") + "(node**)");
QString(), tr("node ") + "(node**)");
if(!res.isEmpty())
ui->nodejsLocation->setText(res);
}
Expand Down
78 changes: 51 additions & 27 deletions src/gui/ExplorerOutputPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,24 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>

#include <cpptools/baseeditordocumentparser.h>

namespace compilerExplorer {
namespace gui{
ExplorerOutputPane::ExplorerOutputPane(QObject *parent)
: Core::IOutputPane(parent),
mExplorer(nullptr),
mCompilerOptions(nullptr),
mRunButton(nullptr),
mBinary(nullptr),
mLabel(nullptr),
mDirectives(nullptr),
mCommentOnly(nullptr),
mIntel(nullptr),
mCurrentCompilerLabel(nullptr),
mCompilersList(nullptr),
mRequestSender(std::make_unique<network::RequestSender>(this)),
mRequestGenerator(std::make_unique<network::RequestGenerator>()){
: Core::IOutputPane(parent),
mExplorer(nullptr),
mCompilerOptions(nullptr),
mRunButton(nullptr),
mBinary(nullptr),
mLabel(nullptr),
mDirectives(nullptr),
mCommentOnly(nullptr),
mIntel(nullptr),
mCurrentCompilerLabel(nullptr),
mCompilersList(nullptr),
mRequestSender(std::make_unique<network::RequestSender>(this)),
mRequestGenerator(std::make_unique<network::RequestGenerator>()){
createTableView();
createCompilerOptions();
createButtons();
Expand All @@ -56,8 +58,8 @@ QWidget *ExplorerOutputPane::outputWidget(QWidget *parent) {
QList<QWidget *> ExplorerOutputPane::toolBarWidgets() const {
QList<QWidget *> result;
result << mRunButton.get() << mCompilerOptions.get() << mBinary.get()
<< mLabel.get() << mDirectives.get() << mCommentOnly.get()
<< mIntel.get() << mCurrentCompilerLabel.get() << mCompilersList.get();
<< mLabel.get() << mDirectives.get() << mCommentOnly.get()
<< mIntel.get() << mCurrentCompilerLabel.get() << mCompilersList.get();
return result;
}

Expand Down Expand Up @@ -134,21 +136,21 @@ void ExplorerOutputPane::createCompilerOptions() {

void ExplorerOutputPane::createButtons() {
mRunButton = createButton(tr("Run"), tr("Send request"),
false, QIcon(":/images/run.png"));
false, QIcon(":/images/run.png"));
mBinary = createButton(tr("11010"),
tr("Compile to binary and disassemble the output"));
tr("Compile to binary and disassemble the output"));
mOptions.insert({mBinary, "binary"});
mLabel = createButton(tr(".LX0:"),
tr("Filter unused labels from the output"));
tr("Filter unused labels from the output"));
mOptions.insert({mLabel, "labels"});
mDirectives = createButton(tr(".text"),
tr("Filter all assembler directives from the output"));
tr("Filter all assembler directives from the output"));
mOptions.insert({mDirectives, "directives"});
mCommentOnly = createButton(tr("//"),
tr("Remove all lines which are only comments from the output"));
tr("Remove all lines which are only comments from the output"));
mOptions.insert({mCommentOnly, "commentOnly"});
mIntel = createButton(tr("Intel"),
tr("Output disassembly in Intel syntax"));
tr("Output disassembly in Intel syntax"));
mOptions.insert({mIntel, "intel"});
connect(mRunButton.get(), &QToolButton::clicked, this, &ExplorerOutputPane::onRunClicked);
}
Expand All @@ -173,15 +175,37 @@ void ExplorerOutputPane::createCompilersList() {
void ExplorerOutputPane::onRunClicked() {
if(!mRequestSender)
return;
mRequestGenerator->setCompilerOptions(mCompilerOptions->text());
mRequestGenerator->setFilters(filters());
QString opts;
QByteArray source;

// Build a command line for the current include paths & defines
if(auto currentDocument = Core::EditorManager::currentDocument())
{
source = currentDocument->contents();

if(auto edit = CppTools::BaseEditorDocumentParser::get(currentDocument->filePath().toString())) {
if(auto part = edit->projectPartInfo().projectPart) {
for(const auto& header : part->headerPaths) {
opts += " -I" + header.path;
}

for(const auto& macro : part->projectMacros) {
opts += " -D" + QString::fromUtf8(macro.key);
if(!macro.value.isEmpty())
opts += "=" + QString::fromUtf8(macro.value);
}
}
}
}


mRequestGenerator->setCompilerOptions(opts + " " + mCompilerOptions->text());
mRequestGenerator->setFilters(filters());
auto unicodeSource = QTextCodec::codecForMib(106)->toUnicode(source); // 106 - utf8
mRequestGenerator->setSourceCode(unicodeSource);
mRequestGenerator->setCompilerLocation(mCompilersList->currentData().toString());
auto request = mRequestGenerator->createCompilerRequest();

auto reply = mRequestSender->sendRequest(std::move(request));
mExplorer->clear();
mExplorer->setText(QTextCodec::codecForMib(106)->toUnicode(reply));
Expand Down Expand Up @@ -209,10 +233,10 @@ void ExplorerOutputPane::updateCompilersList(const QString &address) {
}

std::map<QString, QString> ExplorerOutputPane::compilersList(const QString &address) const {
auto request = network::RequestGenerator::comilersListRequest(address);
auto reply = mRequestSender->sendRequest(std::move(request));
auto parsedCompilersList = network::CompilersListReplyParser::parse(reply);
return parsedCompilersList;
return {
{"%2Fusr%2Fbin%2Fclang%2B%2B", "/usr/bin/clang++"},
{"%2Fusr%2Fbin%2Fg%2B%2B", "/usr/bin/g++"}
};
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/network/GetRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace compilerExplorer {
namespace network{
GetRequest::GetRequest()
: Request() {
: Request() {

}

Expand Down
11 changes: 9 additions & 2 deletions src/network/PostJsonRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace compilerExplorer {
namespace network{

PostJsonRequest::PostJsonRequest()
: GetRequest() {
: GetRequest() {

}

Expand All @@ -29,13 +29,16 @@ QJsonObject PostJsonRequest::jsonRequest(const std::map<QString, QString> &param
for(const auto &param : parameters) {
result.insert(param.first, param.second);
}
QJsonObject options;
options["userArguments"] = mUserArgs;
if(!filters().isEmpty()) {
QJsonObject enabledFilters;
for(auto filter : filters()) {
enabledFilters.insert(filter, "true");
}
result.insert(mFiltersKey, enabledFilters);
options["filters"] = enabledFilters;
}
result["options"] = options;
return result;
}

Expand All @@ -51,6 +54,10 @@ void PostJsonRequest::setFiltersKey(const QString &filtersKey) {
mFiltersKey = filtersKey;
}

void PostJsonRequest::setUserArguments(const QString &opt) {
mUserArgs = opt;
}

QString PostJsonRequest::requestName() const {
return QObject::tr("PostJsonRequest");
}
Expand Down
2 changes: 2 additions & 0 deletions src/network/PostJsonRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class COMPILEREXPLORERSHARED_EXPORT PostJsonRequest : public GetRequest
QStringList filters() const;
void setFilters(const QStringList &filters);
void setFiltersKey(const QString &filtersKey);
void setUserArguments(const QString& opt);
QString requestName() const override;
protected:
QJsonObject jsonRequest() const;
QJsonObject jsonRequest(const std::map<QString, QString> &parameters) const;
private:
QStringList mFilters;
QString mFiltersKey;
QString mUserArgs;
};
}
}
Expand Down
1 change: 1 addition & 0 deletions src/network/PutJsonRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ std::unique_ptr<QNetworkReply> PutJsonRequest::sendRequest(QNetworkAccessManager
url.setQuery(parametersString(mGetParameters));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
request.setUrl(url);

return std::unique_ptr<QNetworkReply>(manager->put(request, QJsonDocument(jsonRequest(mPostParameters)).toJson()));
}

Expand Down
8 changes: 4 additions & 4 deletions src/network/RequestGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class RequestGeneratorPrivate
};

RequestGenerator::RequestGenerator()
: RequestGenerator(QString(), 0) {
: RequestGenerator(QString(), 0) {
}

RequestGenerator::RequestGenerator(const QString &address, const int port)
: d(std::make_unique<RequestGeneratorPrivate>()) {
: d(std::make_unique<RequestGeneratorPrivate>()) {
d->address = address;
d->port = port;
}
Expand All @@ -41,7 +41,7 @@ std::unique_ptr<Request> RequestGenerator::createCompilerRequest() {
result->setAddress(QString("%1/api/compiler/%2/compile").arg(d->address).arg(d->compilerLocation));
result->addParameter(compilerLocationKey, d->compilerLocation);
result->addParameter(sourceCodeKey, d->sourceCode);
result->addParameter(compilerOptionsKey, d->compilerOptions);
result->setUserArguments(d->compilerOptions);
result->setFilters(d->filters);
result->setFiltersKey(filtersKey);
return std::move(result);
Expand Down Expand Up @@ -98,7 +98,7 @@ void RequestGenerator::updateSettings(const QSettings &settings) {
setPort(port);
}

std::unique_ptr<Request> RequestGenerator::comilersListRequest(const QString &address) {
std::unique_ptr<Request> RequestGenerator::compilersListRequest(const QString &address) {
auto result = std::make_unique<GetRequest>();
auto serverAddress = address;
if (serverAddress.endsWith("/")) {
Expand Down
2 changes: 1 addition & 1 deletion src/network/RequestGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class COMPILEREXPLORERSHARED_EXPORT RequestGenerator
void setSourceCode(const QString &code);
void setFilters(const QStringList &filters);
void updateSettings(const QSettings &settings);
static std::unique_ptr<Request> comilersListRequest(const QString &address);
static std::unique_ptr<Request> compilersListRequest(const QString &address);
private:
std::unique_ptr<RequestGeneratorPrivate> d;
};
Expand Down
2 changes: 2 additions & 0 deletions src/qt_deps.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
QTC_SOURCE = "/tmp/qt-creator-opensource-src-4.5.0"
QTC_BUILD = "/opt/qtcreator/"
3 changes: 2 additions & 1 deletion src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ QTC_LIB_DEPENDS += \

QTC_PLUGIN_DEPENDS += \
coreplugin \
projectexplorer
projectexplorer \
cpptools

include($$IDE_SOURCE_TREE/src/qtcreatorplugin.pri)

Expand Down

0 comments on commit 5653f37

Please sign in to comment.