Skip to content
This repository was archived by the owner on Mar 1, 2022. It is now read-only.

Commit ed00edd

Browse files
author
WebFreak001
committed
Embedded dub build
1 parent acccf8d commit ed00edd

File tree

2 files changed

+107
-7
lines changed

2 files changed

+107
-7
lines changed

dub.json

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22
"name": "workspace-d",
33
"description": "A minimal D application.",
44
"copyright": "Copyright © 2015, webfreak",
5-
"authors": ["webfreak"],
6-
"dependencies":
7-
{
5+
"authors": [
6+
"webfreak"
7+
],
8+
"dependencies": {
89
"dub": "~>0.9.24",
910
"painlessjson": "~>1.3.5"
1011
},
12+
"configurations": [
13+
{
14+
"name": "application",
15+
"sourcePaths": [
16+
"source"
17+
],
18+
"targetType": "executable"
19+
}
20+
],
1121
"subPackages": [
1222
"./test"
1323
]
14-
}
24+
}

source/com/dub.d

+93-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import core.sync.mutex;
44
import core.thread;
55

66
import std.json : JSONValue;
7+
import std.conv;
78
import std.stdio;
9+
import std.regex;
10+
import std.string;
811
import std.parallelism;
912
import std.algorithm;
1013

@@ -16,14 +19,21 @@ import dub.dub;
1619
import dub.project;
1720
import dub.package_;
1821
import dub.description;
22+
23+
import dub.generators.generator;
1924
import dub.compilers.compiler;
25+
2026
import dub.compilers.buildsettings;
27+
2128
import dub.internal.vibecompat.inet.url;
29+
import dub.internal.vibecompat.core.log;
2230

2331
@component("dub") :
2432

2533
@load void startup(string dir, bool registerImportProvider = true, bool registerStringImportProvider = true)
2634
{
35+
setLogLevel(LogLevel.none);
36+
2737
if (registerImportProvider)
2838
importPathProvider = &imports;
2939
if (registerStringImportProvider)
@@ -135,7 +145,7 @@ auto configurations() @property
135145
auto buildTypes() @property
136146
{
137147
string[] types = ["plain", "debug", "release", "release-nobounds", "unittest", "docs", "ddox", "profile", "profile-gc", "cov", "unittest-cov"];
138-
foreach(type, info; _dub.project.rootPackage.info.buildTypes)
148+
foreach (type, info; _dub.project.rootPackage.info.buildTypes)
139149
types ~= type;
140150
return types;
141151
}
@@ -166,7 +176,7 @@ bool setBuildType(JSONValue request)
166176
{
167177
assert("build-type" in request, "build-type not in request");
168178
auto type = request["build-type"].fromJSON!string;
169-
if(buildTypes.canFind(type))
179+
if (buildTypes.canFind(type))
170180
{
171181
_buildType = type;
172182
return updateImportPaths(false);
@@ -209,6 +219,68 @@ auto path() @property
209219
return _dub.projectPath;
210220
}
211221

222+
@arguments("subcmd", "build")
223+
@async void build(AsyncCallback cb)
224+
{
225+
new Thread({
226+
try
227+
{
228+
string compilerName = .compiler;
229+
auto compiler = getCompiler(compilerName);
230+
auto buildPlatform = compiler.determinePlatform(_settings, compilerName);
231+
232+
GeneratorSettings settings;
233+
settings.platform = buildPlatform;
234+
settings.config = _configuration;
235+
settings.buildType = _buildType;
236+
settings.compiler = compiler;
237+
settings.buildSettings = _settings;
238+
settings.buildSettings.options |= BuildOption.syntaxOnly;
239+
settings.combined = true;
240+
settings.run = false;
241+
242+
BuildIssue[] issues;
243+
244+
settings.compileCallback = (status, output) {
245+
string[] lines = output.splitLines;
246+
foreach (line;
247+
lines)
248+
{
249+
auto match = line.matchFirst(errorFormat);
250+
if (match)
251+
{
252+
issues ~= BuildIssue(match[2].to!int, match[3].to!int, match[1], match[4].to!ErrorType, match[5]);
253+
}
254+
else
255+
{
256+
if (line.canFind("from"))
257+
{
258+
auto contMatch = line.matchFirst(errorFormatCont);
259+
if (contMatch)
260+
{
261+
issues ~= BuildIssue(contMatch[2].to!int, contMatch[3].to!int, contMatch[1], ErrorType.Error, contMatch[4]);
262+
}
263+
}
264+
}
265+
}
266+
};
267+
try
268+
{
269+
_dub.generateProject("build", settings);
270+
}
271+
catch (Exception e)
272+
{
273+
}
274+
cb(null, issues.toJSON);
275+
}
276+
catch (Throwable t)
277+
{
278+
ubyte[] empty;
279+
cb(t, empty.toJSON);
280+
}
281+
}).start();
282+
}
283+
212284
private __gshared:
213285

214286
Dub _dub;
@@ -221,6 +293,24 @@ Compiler _compiler;
221293
BuildPlatform _platform;
222294
string[] _importPaths, _stringImportPaths;
223295

296+
auto errorFormat = ctRegex!(`(.*?)\((\d+),(\d+)\): (Deprecation|Warning|Error): (.*)`, "gi"); // `
297+
auto errorFormatCont = ctRegex!(`(.*?)\((\d+),(\d+)\): (.*)`, "g"); // `
298+
299+
enum ErrorType : ubyte
300+
{
301+
Error = 0,
302+
Warning = 1,
303+
Deprecation = 2
304+
}
305+
306+
struct BuildIssue
307+
{
308+
int line, column;
309+
string file;
310+
ErrorType type;
311+
string text;
312+
}
313+
224314
struct DubPackageInfo
225315
{
226316
string[string] dependencies;
@@ -251,4 +341,4 @@ auto listDependencies(Project project)
251341
dependencies ~= getInfo(dep);
252342
}
253343
return dependencies;
254-
}
344+
}

0 commit comments

Comments
 (0)