Skip to content

Commit 416596a

Browse files
committed
utils/stdlib_detect: Support directory form of ldc2.conf
See-Also: ldc-developers/ldc#4954 Signed-off-by: Andrei Horodniceanu <[email protected]>
1 parent b280260 commit 416596a

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

source/served/utils/stdlib_detect.d

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module served.utils.stdlib_detect;
22

33
import std.algorithm : countUntil, splitter, startsWith;
4-
import std.array : appender, replace;
4+
import std.array : Appender, appender, replace;
55
import std.ascii : isWhite;
66
import std.conv : to;
77
import std.experimental.logger : trace, warning;
@@ -359,9 +359,39 @@ bool parseDmdConfImports(R)(R confPath, scope const(char)[] confDirPath, out str
359359

360360
bool parseLdcConfImports(string confPath, scope const(char)[] binDirPath, out string[] paths)
361361
{
362-
import external.ldc.config;
362+
Appender!(string[]) ret;
363+
scope(exit) paths = ret.data;
363364

364-
auto ret = appender!(string[]);
365+
import std.algorithm;
366+
import std.array;
367+
import std.file;
368+
369+
if (confPath.isDir)
370+
{
371+
auto configFiles = confPath.dirEntries(SpanMode.shallow)
372+
.filter!`a.isFile`
373+
.map!`a.name`
374+
// FIXME this should be numeric sort
375+
.array
376+
.sort;
377+
378+
import std.conv;
379+
trace("the config files are: ", text(configFiles));
380+
381+
foreach (file; configFiles)
382+
parseLdcConfImportsSingleFile(file, binDirPath, ret);
383+
}
384+
else
385+
parseLdcConfImportsSingleFile(confPath, binDirPath, ret);
386+
387+
if (!ret.data.length)
388+
warning("failed to find phobos/druntime paths in ldc conf ", confPath, " - going to continue looking elsewhere...");
389+
return ret.data.length > 0;
390+
}
391+
392+
void parseLdcConfImportsSingleFile(string confPath, scope const(char)[] binDirPath, ref Appender!(string[]) ret)
393+
{
394+
import external.ldc.config;
365395

366396
binDirPath = binDirPath.replace('\\', '/');
367397

@@ -401,11 +431,6 @@ bool parseLdcConfImports(string confPath, scope const(char)[] binDirPath, out st
401431
parseSection(cast(GroupSetting) s);
402432
}
403433
}
404-
405-
paths = ret.data;
406-
if (!ret.data.length)
407-
warning("failed to find phobos/druntime paths in ldc conf ", confPath, " - going to continue looking elsewhere...");
408-
return ret.data.length > 0;
409434
}
410435

411436
deprecated string[] parseDflagsImports(scope const(char)[] options, bool windows)

0 commit comments

Comments
 (0)