support build, run and different build configurations with dub

This commit is contained in:
Vadim Lopatin 2015-01-29 16:52:32 +03:00
parent 13e06670b9
commit 6f2844a1df
3 changed files with 94 additions and 7 deletions

View File

@ -2,6 +2,7 @@ module dlangide.builders.builder;
import dlangui.core.logger;
import dlangide.workspace.project;
import dlangide.workspace.workspace;
import dlangide.ui.outputpanel;
import dlangide.builders.extprocess;
import dlangui.widgets.appframe;
@ -15,12 +16,18 @@ class Builder : BackgroundOperationWatcher {
protected ExternalProcess _extprocess;
protected OutputPanel _log;
protected ProtectedTextStorage _box;
protected BuildConfiguration _buildConfig;
protected BuildOperation _buildOp;
protected bool _verbose;
@property Project project() { return _project; }
@property void project(Project p) { _project = p; }
this(AppFrame frame, Project project, OutputPanel log) {
this(AppFrame frame, Project project, OutputPanel log, BuildConfiguration buildConfig, BuildOperation buildOp, bool verbose) {
super(frame);
_buildConfig = buildConfig;
_buildOp = buildOp;
_verbose = verbose;
_project = project;
_log = log;
_extprocess = new ExternalProcess();
@ -46,9 +53,36 @@ class Builder : BackgroundOperationWatcher {
char[] program = "dub".dup;
char[][] params;
char[] dir = _project.dir.dup;
params ~= "build".dup;
params ~= "-v".dup;
params ~= "--force".dup;
if (_buildOp == BuildOperation.Build || _buildOp == BuildOperation.Rebuild) {
params ~= "build".dup;
if (_buildOp == BuildOperation.Rebuild) {
params ~= "--force".dup;
}
} else if (_buildOp == BuildOperation.Clean) {
params ~= "clean".dup;
} else if (_buildOp == BuildOperation.Run) {
params ~= "run".dup;
}
if (_buildOp != BuildOperation.Clean) {
switch (_buildConfig) {
default:
case BuildConfiguration.Debug:
params ~= "--build=debug".dup;
break;
case BuildConfiguration.Release:
params ~= "--build=release".dup;
break;
case BuildConfiguration.Unittest:
params ~= "--build=unittest".dup;
break;
}
}
if (_verbose)
params ~= "-v".dup;
state = _extprocess.run(program, params, dir, _box, null);
if (state != ExternalProcessState.Running) {
_box.writeText("Failed to run builder tool\n"d);

View File

@ -338,6 +338,24 @@ class IDEFrame : AppFrame {
tb.addButtons(ACTION_DEBUG_START);
ToolBarComboBox cbBuildConfiguration = new ToolBarComboBox("buildConfig", ["Debug"d, "Release"d, "Unittest"d]);
cbBuildConfiguration.onItemClickListener = delegate(Widget source, int index) {
if (currentWorkspace) {
switch(index) {
case 0:
currentWorkspace.buildConfiguration = BuildConfiguration.Debug;
break;
case 1:
currentWorkspace.buildConfiguration = BuildConfiguration.Release;
break;
case 2:
currentWorkspace.buildConfiguration = BuildConfiguration.Unittest;
break;
default:
break;
}
}
return true;
};
tb.addControl(cbBuildConfiguration);
tb.addButtons(ACTION_PROJECT_BUILD);
@ -379,7 +397,23 @@ class IDEFrame : AppFrame {
return true;
case IDEActions.BuildProject:
case IDEActions.BuildWorkspace:
buildProject();
buildProject(BuildOperation.Build);
//setBackgroundOperation(new BackgroundOperationWatcherTest(this));
return true;
case IDEActions.RebuildProject:
case IDEActions.RebuildWorkspace:
buildProject(BuildOperation.Rebuild);
//setBackgroundOperation(new BackgroundOperationWatcherTest(this));
return true;
case IDEActions.CleanProject:
case IDEActions.CleanWorkspace:
buildProject(BuildOperation.Clean);
//setBackgroundOperation(new BackgroundOperationWatcherTest(this));
return true;
case IDEActions.DebugStart:
case IDEActions.DebugStartNoDebug:
case IDEActions.DebugContinue:
buildProject(BuildOperation.Run);
//setBackgroundOperation(new BackgroundOperationWatcherTest(this));
return true;
case IDEActions.WindowCloseAllDocuments:
@ -473,10 +507,10 @@ class IDEFrame : AppFrame {
_wsPanel.workspace = ws;
}
void buildProject() {
void buildProject(BuildOperation buildOp) {
if (!currentWorkspace || !currentWorkspace.startupProject)
return;
Builder op = new Builder(this, currentWorkspace.startupProject, _logPanel);
Builder op = new Builder(this, currentWorkspace.startupProject, _logPanel, currentWorkspace.buildConfiguration, buildOp, false);
setBackgroundOperation(op);
}
}

View File

@ -8,6 +8,20 @@ import std.json;
import std.utf;
import std.algorithm;
enum BuildOperation {
Build,
Clean,
Rebuild,
Run
}
enum BuildConfiguration {
Debug,
Release,
Unittest
}
/**
Exception thrown on Workspace errors
*/
@ -30,6 +44,8 @@ bool isWorkspaceFile(string filename) {
class Workspace : WorkspaceItem {
protected Project[] _projects;
protected BuildConfiguration _buildConfiguration;
this(string fname = null) {
super(fname);
}
@ -38,6 +54,9 @@ class Workspace : WorkspaceItem {
return _projects;
}
@property BuildConfiguration buildConfiguration() { return _buildConfiguration; }
@property void buildConfiguration(BuildConfiguration config) { _buildConfiguration = config; }
protected Project _startupProject;
@property Project startupProject() { return _startupProject; }