Skip to content

Commit fabb1b2

Browse files
denizzzkathewilsonator
authored andcommitted
ldc2.conf: %%ldcconfigpath%% placeholder added
1 parent 9485a1e commit fabb1b2

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

67
#### Platform support
78

driver/configfile.d

+24-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import core.stdc.stdio;
1818
import core.stdc.string;
1919

2020

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

99+
struct CfgPaths
100+
{
101+
string cfgBaseDir; /// ldc2.conf directory
102+
string ldcBinaryDir; /// ldc2.exe binary dir
103+
104+
this(const(char)* cfPath, const(char)* binDir)
105+
{
106+
import dmd.root.filename: FileName;
107+
108+
cfgBaseDir = normalizeSlashes(FileName.path(cfPath));
109+
ldcBinaryDir = normalizeSlashes(binDir);
110+
}
111+
}
112+
113+
string replacePlaceholders(string str, CfgPaths cfgPaths)
114+
{
115+
return str
116+
.replace("%%ldcbinarypath%%", cfgPaths.ldcBinaryDir)
117+
.replace("%%ldcconfigpath%%", cfgPaths.cfgBaseDir);
118+
}
99119

100120
extern(C++) struct ConfigFile
101121
{
@@ -117,8 +137,7 @@ private:
117137
{
118138
switches.setDim(0);
119139
postSwitches.setDim(0);
120-
121-
immutable dBinDir = prepareBinDir(binDir);
140+
const cfgPaths = CfgPaths(cfPath, binDir);
122141

123142
try
124143
{
@@ -156,7 +175,7 @@ private:
156175
output.reserve(input.vals.length);
157176
foreach (sw; input.vals)
158177
{
159-
const finalSwitch = sw.replace("%%ldcbinarypath%%", dBinDir) ~ '\0';
178+
const finalSwitch = sw.replacePlaceholders(cfgPaths) ~ '\0';
160179
output.push(finalSwitch.ptr);
161180
}
162181
}
@@ -168,7 +187,7 @@ private:
168187
applyArray(_libDirs, libDirs);
169188

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

173192
return true;
174193
}

0 commit comments

Comments
 (0)