-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScratchcc.cpp
49 lines (44 loc) · 1.75 KB
/
Scratchcc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "Scratchcc.h"
#include <QProcess>
#include <QTemporaryFile>
#include <QDir>
#include <QSettings>
Scratchcc::Scratchcc(const QString &sourceFile, const QString &resultFile, QObject *parent) :
QObject(parent),
source_(sourceFile),
dest_(resultFile)
{
}
void Scratchcc::compile()
{
QSettings settings;
QString scratchccPath = QDir::fromNativeSeparators(settings.value("ScratchccPath").toString());
compileProcess_ = new QProcess(this);
compileProcess_->setProcessChannelMode(QProcess::ForwardedChannels);
connect(compileProcess_, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(processFinished(int,QProcess::ExitStatus)));
connect(compileProcess_, SIGNAL(error(QProcess::ProcessError)), SLOT(processError(QProcess::ProcessError)));
#ifdef Q_OS_WIN
QString elixerExecutable = "elixir.bat";
#else
QString elixerExecutable = "elixir";
#endif
compileProcess_->start(elixerExecutable, QStringList() << "-pa" << scratchccPath + "/_build/dev/lib/scratchcc/ebin" <<
"-pa" << scratchccPath + "/_build/dev/lib/jsex/ebin" <<
"-pa" << scratchccPath + "/_build/dev/lib/jsx/ebin" <<
"-e" << QString("Scratchcc.doit(\"%1\", \"%2\")").arg(QDir::fromNativeSeparators(source_)).arg(QDir::fromNativeSeparators(dest_)) <<
"-e" << "\":init.stop\"");
}
void Scratchcc::processError(QProcess::ProcessError e)
{
Q_UNUSED(e);
QString errorMessage = compileProcess_->errorString();
emit error(errorMessage);
}
void Scratchcc::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
if (exitCode == 0 && exitStatus == QProcess::NormalExit) {
emit complete();
} else {
emit error(QString("Compile process failed with code %1").arg(exitCode));
}
}