can build current project with dub

This commit is contained in:
Vadim Lopatin 2015-01-28 23:10:31 +03:00
parent 52040619c9
commit f9183b9038
4 changed files with 34 additions and 14 deletions

View File

@ -39,7 +39,7 @@ extern (C) int UIAppMain(string[] args) {
// open home screen tab // open home screen tab
frame.showHomeScreen(); frame.showHomeScreen();
// for testing: load workspace at startup // for testing: load workspace at startup
//frame.loadWorkspace(appendPath(exePath, "../workspaces/sample1/sample1.dlangidews")); frame.openFileOrWorkspace(appendPath(exePath, "../workspaces/sample1/sample1.dlangidews"));
// show window // show window
window.show(); window.show();

View File

@ -1,10 +1,12 @@
module dlangide.builders.builder; module dlangide.builders.builder;
import dlangui.core.logger;
import dlangide.workspace.project; import dlangide.workspace.project;
import dlangide.ui.outputpanel; import dlangide.ui.outputpanel;
import dlangide.builders.extprocess; import dlangide.builders.extprocess;
import dlangui.widgets.appframe; import dlangui.widgets.appframe;
import std.algorithm; import std.algorithm;
import core.thread;
import std.string; import std.string;
import std.conv; import std.conv;
@ -21,6 +23,7 @@ class Builder : BackgroundOperationWatcher, ProcessOutputTarget {
_project = project; _project = project;
_log = log; _log = log;
_extprocess = new ExternalProcess(); _extprocess = new ExternalProcess();
Log.d("Builder.this");
} }
/// log lines /// log lines
override void onText(dstring text) { override void onText(dstring text) {
@ -32,18 +35,20 @@ class Builder : BackgroundOperationWatcher, ProcessOutputTarget {
override @property string icon() { return "folder"; } override @property string icon() { return "folder"; }
/// update background operation status /// update background operation status
override void update() { override void update() {
if (_extprocess.state == ExternalProcessState.None) { ExternalProcessState state = _extprocess.state;
if (state == ExternalProcessState.None) {
_log.clear();
onText("Running dub\n"d); onText("Running dub\n"d);
_extprocess.run(cast(char[])"dub", cast(char[][])["build"], cast(char[])_project.dir, this, null); state = _extprocess.run(cast(char[])"dub", cast(char[][])["build"], cast(char[])_project.dir, this, null);
if (_extprocess.state != ExternalProcessState.Running) { if (state != ExternalProcessState.Running) {
onText("Failed to run builder tool"); onText("Failed to run builder tool\n");
_finished = true; _finished = true;
destroy(_extprocess); destroy(_extprocess);
_extprocess = null; _extprocess = null;
return; return;
} }
} }
ExternalProcessState state = _extprocess.poll(); state = _extprocess.poll();
if (state == ExternalProcessState.Stopped) { if (state == ExternalProcessState.Stopped) {
onText("Builder finished with result "d ~ to!dstring(_extprocess.result) ~ "\n"d); onText("Builder finished with result "d ~ to!dstring(_extprocess.result) ~ "\n"d);
_finished = true; _finished = true;

View File

@ -3,7 +3,7 @@ module dlangide.builders.extprocess;
import dlangui.core.logger; import dlangui.core.logger;
import std.process; import std.process;
import std.file; import std.stdio;
import std.utf; import std.utf;
/// interface to forward process output to /// interface to forward process output to
@ -52,8 +52,9 @@ class ExternalProcess {
_args = args; _args = args;
_workDir = dir; _workDir = dir;
_stdout = stdoutTarget; _stdout = stdoutTarget;
_stdoutBuffer.clear(); _stdoutBuffer = new Buffer();
_stderrBuffer.clear(); if (stderrTarget)
_stderrBuffer = new Buffer();
_result = 0; _result = 0;
assert(_stdout); assert(_stdout);
_stderr = stderrTarget; _stderr = stderrTarget;
@ -62,12 +63,12 @@ class ExternalProcess {
params ~= _program; params ~= _program;
params ~= _args; params ~= _args;
if (!_stderr) if (!_stderr)
redirect = Redirect.stdin | Redirect.stderrToStdout; redirect = Redirect.stdout | Redirect.stdin | Redirect.stderrToStdout;
else else
redirect = Redirect.all; redirect = Redirect.all;
Log.i("Trying to run program ", _program, " with args ", _args); Log.i("Trying to run program ", _program, " with args ", _args);
try { try {
_pipes = pipeProcess(params, redirect, _env, Config.none, _workDir); _pipes = pipeProcess(params, redirect, _env, Config.suppressConsole, _workDir);
_state = ExternalProcessState.Running; _state = ExternalProcessState.Running;
_stdoutBuffer.init(); _stdoutBuffer.init();
if (_stderr) if (_stderr)
@ -100,7 +101,7 @@ class ExternalProcess {
for(size_t i = 0; i < data.length; i++) for(size_t i = 0; i < data.length; i++)
bytes[len++] = data[i]; bytes[len++] = data[i];
} }
size_t read(std.file.File file) { size_t read(std.stdio.File file) {
size_t bytesRead = 0; size_t bytesRead = 0;
for (;;) { for (;;) {
ubyte[] readData = file.rawRead(buffer); ubyte[] readData = file.rawRead(buffer);
@ -169,7 +170,7 @@ class ExternalProcess {
protected Buffer _stdoutBuffer; protected Buffer _stdoutBuffer;
protected Buffer _stderrBuffer; 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) { if (src.isOpen) {
buffer.read(src); buffer.read(src);
dstring s = buffer.text; dstring s = buffer.text;
@ -188,12 +189,19 @@ class ExternalProcess {
if (_stderr) if (_stderr)
res = poll(_stderr, _pipes.stderr, _stderrBuffer) && res; res = poll(_stderr, _pipes.stderr, _stderrBuffer) && res;
} catch (Error e) { } 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; res = false;
} }
return res; return res;
} }
void closeFiles() {
_pipes.stdout.close();
_pipes.stdin.close();
if (_stderr)
_pipes.stderr.close();
}
/// polls all available output from process streams /// polls all available output from process streams
ExternalProcessState poll() { ExternalProcessState poll() {
bool res = true; bool res = true;
@ -208,6 +216,7 @@ class ExternalProcess {
if (pstate.terminated) { if (pstate.terminated) {
pollStreams(); pollStreams();
_state = ExternalProcessState.Stopped; _state = ExternalProcessState.Stopped;
closeFiles();
_result = pstate.status; _result = pstate.status;
} }
} catch (Exception e) { } catch (Exception e) {
@ -224,6 +233,8 @@ class ExternalProcess {
try { try {
_result = std.process.wait(_pipes.pid); _result = std.process.wait(_pipes.pid);
_state = ExternalProcessState.Stopped; _state = ExternalProcessState.Stopped;
pollStreams();
closeFiles();
} catch (Exception e) { } catch (Exception e) {
Log.e("Exception while waiting for process ", _program); Log.e("Exception while waiting for process ", _program);
_state = ExternalProcessState.Error; _state = ExternalProcessState.Error;

View File

@ -23,4 +23,8 @@ class OutputPanel : DockWindow {
void addLogLines(string category, dstring[] msg...) { void addLogLines(string category, dstring[] msg...) {
_logWidget.appendLines(msg); _logWidget.appendLines(msg);
} }
void clear(string category = null) {
_logWidget.text = ""d;
}
} }