@@ -166,6 +166,8 @@ public struct CompileCommand
166
166
string [] args;
167
167
string output;
168
168
169
+ private bool argsAdjusted;
170
+
169
171
private static CompileCommand fromJson (JSONValue json)
170
172
{
171
173
import std.algorithm : map;
@@ -233,23 +235,88 @@ public struct CompileCommand
233
235
return absolutePath (filename, directory);
234
236
}
235
237
236
- Future! (BuildIssue[]) run () const
238
+ Future! (BuildIssue[]) run ()
237
239
{
238
- import std.algorithm : canFind, remove;
239
240
import std.process : Config, execute;
240
241
242
+ if (! argsAdjusted)
243
+ {
244
+ argsAdjusted = true ;
245
+ adjustArgs();
246
+ }
247
+
241
248
return Future! (BuildIssue[]).async({
242
- trace(" stripping color from " , args);
243
- string [] program = args.dup .remove! (a => a.canFind(" -color=on" ) || a.canFind(
244
- " -enable-color" ));
245
- trace(" running " , program);
246
- auto res = execute(program, null , Config.none, size_t .max, directory);
249
+ trace(" running " , args);
250
+ auto res = execute(args, null , Config.none, size_t .max, directory);
247
251
trace(res.status, " " , res.output);
248
252
auto issues = parseBuildIssues(res.output);
249
253
trace(" found " , issues.length, " issue(s)!" );
250
254
return issues;
251
255
});
252
256
}
257
+
258
+ private void adjustArgs () nothrow
259
+ {
260
+ import std.algorithm : canFind, remove, startsWith;
261
+
262
+ // determine compiler
263
+ const exe = args.length ? args[0 ].baseName : null ;
264
+ if (! exe)
265
+ return ;
266
+
267
+ const isDmd = exe.canFind(" dmd" );
268
+ const isLdc = ! isDmd && exe.canFind(" ldc" );
269
+ const isGdc = ! isDmd && ! isLdc && exe.canFind(" gdc" );
270
+
271
+ if (! isDmd && ! isLdc && ! isGdc)
272
+ return ;
273
+
274
+ version (Posix )
275
+ enum nulFile = " /dev/null" ;
276
+ else version (Windows )
277
+ enum nulFile = " NUL" ;
278
+
279
+ if (isDmd || isLdc)
280
+ {
281
+ const ofArg = isDmd ? " -of" : " --of=" ;
282
+ const columnsArg = isDmd ? " -vcolumns" : " --vcolumns" ;
283
+ bool foundColumns;
284
+
285
+ for (size_t i = 1 ; i < args.length; ++ i)
286
+ {
287
+ if (args[i].startsWith(ofArg))
288
+ {
289
+ args[i] = ofArg ~ nulFile;
290
+ }
291
+ else if (args[i] == columnsArg)
292
+ {
293
+ foundColumns = true ;
294
+ }
295
+ else if (isDmd && args[i].startsWith(" -color" ))
296
+ {
297
+ args[i] = " -color=off" ;
298
+ }
299
+ else if (isLdc && args[i].startsWith(" --enable-color" ))
300
+ {
301
+ args[i] = " --disable-color" ;
302
+ }
303
+ }
304
+
305
+ if (! foundColumns)
306
+ args ~= columnsArg;
307
+ }
308
+ else if (isGdc)
309
+ {
310
+ for (size_t i = 1 ; i < args.length; ++ i)
311
+ {
312
+ if (args[i] == " -o" && (i + 1 ) < args.length)
313
+ {
314
+ args[i + 1 ] = nulFile;
315
+ break ;
316
+ }
317
+ }
318
+ }
319
+ }
253
320
}
254
321
255
322
void feedOptions (
0 commit comments