Skip to content

Commit

Permalink
ldc2.conf: %%ldcconfigpath%% placeholder added
Browse files Browse the repository at this point in the history
  • Loading branch information
denizzzka authored and thewilsonator committed Aug 8, 2024
1 parent 9485a1e commit fabb1b2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### Big news
- Android: NDK for prebuilt package bumped from r26d to r27. (#4711)
- ldc2.conf: %%ldcconfigpath%% placeholder added - specifies the directory where current configuration file is located. (#4717)

#### Platform support

Expand Down
29 changes: 24 additions & 5 deletions driver/configfile.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import core.stdc.stdio;
import core.stdc.string;


string prepareBinDir(const(char)* binDir)
string normalizeSlashes(const(char)* binDir)
{
immutable len = strlen(binDir);
auto res = binDir[0 .. len].dup;
Expand Down Expand Up @@ -96,6 +96,26 @@ unittest
assert(replace(test4, pattern, "word") == "a word, yet other words");
}

struct CfgPaths
{
string cfgBaseDir; /// ldc2.conf directory
string ldcBinaryDir; /// ldc2.exe binary dir

this(const(char)* cfPath, const(char)* binDir)
{
import dmd.root.filename: FileName;

cfgBaseDir = normalizeSlashes(FileName.path(cfPath));
ldcBinaryDir = normalizeSlashes(binDir);
}
}

string replacePlaceholders(string str, CfgPaths cfgPaths)
{
return str
.replace("%%ldcbinarypath%%", cfgPaths.ldcBinaryDir)
.replace("%%ldcconfigpath%%", cfgPaths.cfgBaseDir);
}

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

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

try
{
Expand Down Expand Up @@ -156,7 +175,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 +187,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 fabb1b2

Please sign in to comment.