From fbe98b55d3e518d4cc7f2c844ffff3bc04238c04 Mon Sep 17 00:00:00 2001 From: Andrei Horodniceanu Date: Sun, 3 Aug 2025 01:33:52 +0300 Subject: [PATCH 1/2] utils/stdlib_detect: Support directory form of ldc2.conf See-Also: https://github.com/ldc-developers/ldc/pull/4954 Signed-off-by: Andrei Horodniceanu --- source/served/utils/stdlib_detect.d | 41 +++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/source/served/utils/stdlib_detect.d b/source/served/utils/stdlib_detect.d index f9d81dd..0e2b77f 100644 --- a/source/served/utils/stdlib_detect.d +++ b/source/served/utils/stdlib_detect.d @@ -1,7 +1,7 @@ module served.utils.stdlib_detect; import std.algorithm : countUntil, splitter, startsWith; -import std.array : appender, replace; +import std.array : Appender, appender, replace; import std.ascii : isWhite; import std.conv : to; import std.experimental.logger : trace, warning; @@ -359,9 +359,39 @@ bool parseDmdConfImports(R)(R confPath, scope const(char)[] confDirPath, out str bool parseLdcConfImports(string confPath, scope const(char)[] binDirPath, out string[] paths) { - import external.ldc.config; + Appender!(string[]) ret; + scope(exit) paths = ret.data; - auto ret = appender!(string[]); + import std.algorithm; + import std.array; + import std.file; + + if (confPath.isDir) + { + auto configFiles = confPath.dirEntries(SpanMode.shallow) + .filter!`a.isFile` + .map!`a.name` + // FIXME this should be numeric sort + .array + .sort; + + import std.conv; + trace("the config files are: ", text(configFiles)); + + foreach (file; configFiles) + parseLdcConfImportsSingleFile(file, binDirPath, ret); + } + else + parseLdcConfImportsSingleFile(confPath, binDirPath, ret); + + if (!ret.data.length) + warning("failed to find phobos/druntime paths in ldc conf ", confPath, " - going to continue looking elsewhere..."); + return ret.data.length > 0; +} + +void parseLdcConfImportsSingleFile(string confPath, scope const(char)[] binDirPath, ref Appender!(string[]) ret) +{ + import external.ldc.config; binDirPath = binDirPath.replace('\\', '/'); @@ -401,11 +431,6 @@ bool parseLdcConfImports(string confPath, scope const(char)[] binDirPath, out st parseSection(cast(GroupSetting) s); } } - - paths = ret.data; - if (!ret.data.length) - warning("failed to find phobos/druntime paths in ldc conf ", confPath, " - going to continue looking elsewhere..."); - return ret.data.length > 0; } deprecated string[] parseDflagsImports(scope const(char)[] options, bool windows) From b14bfd01df856c658346bd0bc94c104e570d248f Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Sat, 2 May 2026 20:21:35 +0200 Subject: [PATCH 2/2] fix ldc config parsing twice --- source/served/utils/stdlib_detect.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/served/utils/stdlib_detect.d b/source/served/utils/stdlib_detect.d index 0e2b77f..c6a92a4 100644 --- a/source/served/utils/stdlib_detect.d +++ b/source/served/utils/stdlib_detect.d @@ -259,8 +259,8 @@ private string getUserHomeDirectoryLDC() { version (Windows) { - import core.sys.windows.windows; import core.sys.windows.shlobj; + import core.sys.windows.windows; wchar[MAX_PATH] buf; HRESULT res = SHGetFolderPathW(null, CSIDL_FLAG_CREATE | CSIDL_APPDATA, null, SHGFP_TYPE @@ -424,7 +424,7 @@ void parseLdcConfImportsSingleFile(string confPath, scope const(char)[] binDirPa catch (Exception e) throw new Exception("Could not read ldc2 config file: " ~ confPath ~ ": " ~ e.msg); - foreach (s; parseConfigFile(confPath)) + foreach (s; settings) { if (s.type == Setting.Type.group && s.name == "default") {