Skip to content

Commit

Permalink
ldc2.conf: %%ldcconfigpath%% support added
Browse files Browse the repository at this point in the history
  • Loading branch information
denizzzka committed Jul 31, 2024
1 parent 48c1dff commit b198364
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions driver/configfile.d
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,39 @@ unittest
assert(replace(test4, pattern, "word") == "a word, yet other words");
}

const(char)* baseDir(const(char)* path)
{
import dmd.root.filename: isDirSeparator;

foreach_reverse (i; 0 .. strlen(path))
{
if (path[i-1].isDirSeparator)
{
auto res = path[0 .. i].dup;
res[$-1] = '\0';

return &res[0];
}
}

assert (false);
}

struct CfgPaths
{
const(char)* cfPath; /// ldc2.conf path
const(char)* binDir; /// ldc2.exe binary dir
}

string replacePlaceholders(string str, CfgPaths cfgPaths)
{
immutable dBinDir = prepareBinDir(cfgPaths.binDir);
immutable dCfgDir = prepareBinDir(cfgPaths.cfPath.baseDir);

return str
.replace("%%ldcbinarypath%%", dBinDir)
.replace("%%ldcconfigpath%%", dCfgDir);
}

extern(C++) struct ConfigFile
{
Expand All @@ -117,8 +150,7 @@ private:
{
switches.setDim(0);
postSwitches.setDim(0);

immutable dBinDir = prepareBinDir(binDir);
const CfgPaths cfgPaths = { cfPath: cfPath, binDir: binDir };

try
{
Expand Down Expand Up @@ -156,7 +188,7 @@ private:
output.reserve(input.vals.length);
foreach (sw; input.vals)
{
const finalSwitch = sw.replace("%%ldcbinarypath%%", dBinDir) ~ '\0';
const finalSwitch = sw.replacePlaceholders(cfgPaths) ~ '\0';
output.push(finalSwitch.ptr);
}
}
Expand All @@ -168,7 +200,7 @@ private:
applyArray(_libDirs, libDirs);

if (auto rpath = findScalarSetting(sections, "rpath"))
this.rpathcstr = (rpath.val.replace("%%ldcbinarypath%%", dBinDir) ~ '\0').ptr;
this.rpathcstr = (rpath.val.replacePlaceholders(cfgPaths) ~ '\0').ptr;

return true;
}
Expand Down

0 comments on commit b198364

Please sign in to comment.