@@ -18,7 +18,7 @@ import core.stdc.stdio;
18
18
import core.stdc.string ;
19
19
20
20
21
- string prepareBinDir (const (char )* binDir)
21
+ string normalizeSlashes (const (char )* binDir)
22
22
{
23
23
immutable len = strlen(binDir);
24
24
auto res = binDir[0 .. len].dup ;
@@ -96,6 +96,26 @@ unittest
96
96
assert (replace(test4, pattern, " word" ) == " a word, yet other words" );
97
97
}
98
98
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
+ }
99
119
100
120
extern (C++ ) struct ConfigFile
101
121
{
@@ -117,8 +137,7 @@ private:
117
137
{
118
138
switches.setDim(0 );
119
139
postSwitches.setDim(0 );
120
-
121
- immutable dBinDir = prepareBinDir(binDir);
140
+ const cfgPaths = CfgPaths(cfPath, binDir);
122
141
123
142
try
124
143
{
@@ -156,7 +175,7 @@ private:
156
175
output.reserve (input.vals.length);
157
176
foreach (sw; input.vals)
158
177
{
159
- const finalSwitch = sw.replace( " %%ldcbinarypath%% " , dBinDir ) ~ ' \0 ' ;
178
+ const finalSwitch = sw.replacePlaceholders(cfgPaths ) ~ ' \0 ' ;
160
179
output.push(finalSwitch.ptr);
161
180
}
162
181
}
@@ -168,7 +187,7 @@ private:
168
187
applyArray(_libDirs, libDirs);
169
188
170
189
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;
172
191
173
192
return true ;
174
193
}
0 commit comments