@@ -4,7 +4,10 @@ import core.sync.mutex;
4
4
import core.thread ;
5
5
6
6
import std.json : JSONValue;
7
+ import std.conv ;
7
8
import std.stdio ;
9
+ import std.regex ;
10
+ import std.string ;
8
11
import std.parallelism ;
9
12
import std.algorithm ;
10
13
@@ -16,14 +19,21 @@ import dub.dub;
16
19
import dub.project;
17
20
import dub.package_;
18
21
import dub.description;
22
+
23
+ import dub.generators.generator;
19
24
import dub.compilers.compiler;
25
+
20
26
import dub.compilers.buildsettings;
27
+
21
28
import dub.internal.vibecompat.inet.url;
29
+ import dub.internal.vibecompat.core.log ;
22
30
23
31
@component(" dub" ) :
24
32
25
33
@load void startup(string dir, bool registerImportProvider = true , bool registerStringImportProvider = true )
26
34
{
35
+ setLogLevel(LogLevel.none);
36
+
27
37
if (registerImportProvider)
28
38
importPathProvider = &imports;
29
39
if (registerStringImportProvider)
@@ -135,7 +145,7 @@ auto configurations() @property
135
145
auto buildTypes () @property
136
146
{
137
147
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)
139
149
types ~= type;
140
150
return types;
141
151
}
@@ -166,7 +176,7 @@ bool setBuildType(JSONValue request)
166
176
{
167
177
assert (" build-type" in request, " build-type not in request" );
168
178
auto type = request[" build-type" ].fromJSON! string ;
169
- if (buildTypes.canFind(type))
179
+ if (buildTypes.canFind(type))
170
180
{
171
181
_buildType = type;
172
182
return updateImportPaths (false );
@@ -209,6 +219,68 @@ auto path() @property
209
219
return _dub.projectPath;
210
220
}
211
221
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
+
212
284
private __gshared :
213
285
214
286
Dub _dub;
@@ -221,6 +293,24 @@ Compiler _compiler;
221
293
BuildPlatform _platform;
222
294
string [] _importPaths, _stringImportPaths;
223
295
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
+
224
314
struct DubPackageInfo
225
315
{
226
316
string [string ] dependencies;
@@ -251,4 +341,4 @@ auto listDependencies(Project project)
251
341
dependencies ~= getInfo(dep);
252
342
}
253
343
return dependencies;
254
- }
344
+ }
0 commit comments