mirror of https://github.com/buggins/dlangide.git
can build current project with dub
This commit is contained in:
parent
52040619c9
commit
f9183b9038
|
@ -39,7 +39,7 @@ extern (C) int UIAppMain(string[] args) {
|
|||
// open home screen tab
|
||||
frame.showHomeScreen();
|
||||
// for testing: load workspace at startup
|
||||
//frame.loadWorkspace(appendPath(exePath, "../workspaces/sample1/sample1.dlangidews"));
|
||||
frame.openFileOrWorkspace(appendPath(exePath, "../workspaces/sample1/sample1.dlangidews"));
|
||||
|
||||
// show window
|
||||
window.show();
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
module dlangide.builders.builder;
|
||||
|
||||
import dlangui.core.logger;
|
||||
import dlangide.workspace.project;
|
||||
import dlangide.ui.outputpanel;
|
||||
import dlangide.builders.extprocess;
|
||||
import dlangui.widgets.appframe;
|
||||
import std.algorithm;
|
||||
import core.thread;
|
||||
import std.string;
|
||||
import std.conv;
|
||||
|
||||
|
@ -21,6 +23,7 @@ class Builder : BackgroundOperationWatcher, ProcessOutputTarget {
|
|||
_project = project;
|
||||
_log = log;
|
||||
_extprocess = new ExternalProcess();
|
||||
Log.d("Builder.this");
|
||||
}
|
||||
/// log lines
|
||||
override void onText(dstring text) {
|
||||
|
@ -32,18 +35,20 @@ class Builder : BackgroundOperationWatcher, ProcessOutputTarget {
|
|||
override @property string icon() { return "folder"; }
|
||||
/// update background operation status
|
||||
override void update() {
|
||||
if (_extprocess.state == ExternalProcessState.None) {
|
||||
ExternalProcessState state = _extprocess.state;
|
||||
if (state == ExternalProcessState.None) {
|
||||
_log.clear();
|
||||
onText("Running dub\n"d);
|
||||
_extprocess.run(cast(char[])"dub", cast(char[][])["build"], cast(char[])_project.dir, this, null);
|
||||
if (_extprocess.state != ExternalProcessState.Running) {
|
||||
onText("Failed to run builder tool");
|
||||
state = _extprocess.run(cast(char[])"dub", cast(char[][])["build"], cast(char[])_project.dir, this, null);
|
||||
if (state != ExternalProcessState.Running) {
|
||||
onText("Failed to run builder tool\n");
|
||||
_finished = true;
|
||||
destroy(_extprocess);
|
||||
_extprocess = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
ExternalProcessState state = _extprocess.poll();
|
||||
state = _extprocess.poll();
|
||||
if (state == ExternalProcessState.Stopped) {
|
||||
onText("Builder finished with result "d ~ to!dstring(_extprocess.result) ~ "\n"d);
|
||||
_finished = true;
|
||||
|
|
|
@ -3,7 +3,7 @@ module dlangide.builders.extprocess;
|
|||
import dlangui.core.logger;
|
||||
|
||||
import std.process;
|
||||
import std.file;
|
||||
import std.stdio;
|
||||
import std.utf;
|
||||
|
||||
/// interface to forward process output to
|
||||
|
@ -52,8 +52,9 @@ class ExternalProcess {
|
|||
_args = args;
|
||||
_workDir = dir;
|
||||
_stdout = stdoutTarget;
|
||||
_stdoutBuffer.clear();
|
||||
_stderrBuffer.clear();
|
||||
_stdoutBuffer = new Buffer();
|
||||
if (stderrTarget)
|
||||
_stderrBuffer = new Buffer();
|
||||
_result = 0;
|
||||
assert(_stdout);
|
||||
_stderr = stderrTarget;
|
||||
|
@ -62,12 +63,12 @@ class ExternalProcess {
|
|||
params ~= _program;
|
||||
params ~= _args;
|
||||
if (!_stderr)
|
||||
redirect = Redirect.stdin | Redirect.stderrToStdout;
|
||||
redirect = Redirect.stdout | Redirect.stdin | Redirect.stderrToStdout;
|
||||
else
|
||||
redirect = Redirect.all;
|
||||
Log.i("Trying to run program ", _program, " with args ", _args);
|
||||
try {
|
||||
_pipes = pipeProcess(params, redirect, _env, Config.none, _workDir);
|
||||
_pipes = pipeProcess(params, redirect, _env, Config.suppressConsole, _workDir);
|
||||
_state = ExternalProcessState.Running;
|
||||
_stdoutBuffer.init();
|
||||
if (_stderr)
|
||||
|
@ -100,7 +101,7 @@ class ExternalProcess {
|
|||
for(size_t i = 0; i < data.length; i++)
|
||||
bytes[len++] = data[i];
|
||||
}
|
||||
size_t read(std.file.File file) {
|
||||
size_t read(std.stdio.File file) {
|
||||
size_t bytesRead = 0;
|
||||
for (;;) {
|
||||
ubyte[] readData = file.rawRead(buffer);
|
||||
|
@ -169,7 +170,7 @@ class ExternalProcess {
|
|||
protected Buffer _stdoutBuffer;
|
||||
protected Buffer _stderrBuffer;
|
||||
|
||||
protected bool poll(ProcessOutputTarget dst, std.file.File src, ref Buffer buffer) {
|
||||
protected bool poll(ProcessOutputTarget dst, std.stdio.File src, ref Buffer buffer) {
|
||||
if (src.isOpen) {
|
||||
buffer.read(src);
|
||||
dstring s = buffer.text;
|
||||
|
@ -188,12 +189,19 @@ class ExternalProcess {
|
|||
if (_stderr)
|
||||
res = poll(_stderr, _pipes.stderr, _stderrBuffer) && res;
|
||||
} catch (Error e) {
|
||||
Log.e("error occued while trying to poll streams for process ", _program);
|
||||
Log.e("error occued while trying to poll streams for process ", _program, " : ", e);
|
||||
res = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void closeFiles() {
|
||||
_pipes.stdout.close();
|
||||
_pipes.stdin.close();
|
||||
if (_stderr)
|
||||
_pipes.stderr.close();
|
||||
}
|
||||
|
||||
/// polls all available output from process streams
|
||||
ExternalProcessState poll() {
|
||||
bool res = true;
|
||||
|
@ -208,6 +216,7 @@ class ExternalProcess {
|
|||
if (pstate.terminated) {
|
||||
pollStreams();
|
||||
_state = ExternalProcessState.Stopped;
|
||||
closeFiles();
|
||||
_result = pstate.status;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -224,6 +233,8 @@ class ExternalProcess {
|
|||
try {
|
||||
_result = std.process.wait(_pipes.pid);
|
||||
_state = ExternalProcessState.Stopped;
|
||||
pollStreams();
|
||||
closeFiles();
|
||||
} catch (Exception e) {
|
||||
Log.e("Exception while waiting for process ", _program);
|
||||
_state = ExternalProcessState.Error;
|
||||
|
|
|
@ -23,4 +23,8 @@ class OutputPanel : DockWindow {
|
|||
void addLogLines(string category, dstring[] msg...) {
|
||||
_logWidget.appendLines(msg);
|
||||
}
|
||||
|
||||
void clear(string category = null) {
|
||||
_logWidget.text = ""d;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue