Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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