Skip to content

Commit 0030b9a

Browse files
the-horothewilsonator
authored andcommitted
compilers/dmd: Determine the backend version for gdmd
This changes makes the compiler version for gdmd match the gdc version instead of the dmd FE version that gdc had been using. This matches what happens for ldmd2 which mirrors the ldc2 version. Specifically, now the versions look like: - ldmd2-1.40 :: 1.40.X - ldc2-1.40 :: 1.40.X - gdc-14 :: 14.X.Y - gdmd-14 :: 14.X.Y When, previously, gdmd-14 would result in a version like 2.108.X Signed-off-by: Andrei Horodniceanu <a.horodniceanu@proton.me>
1 parent ad3f246 commit 0030b9a

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

source/dub/compilers/compiler.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ interface Compiler {
132132
string[] lflagsToDFlags(const string[] lflags) const;
133133

134134
/// Determines compiler version
135-
string determineVersion(string compiler_binary, string verboseOutput);
135+
string determineVersion(in BuildPlatform platform, string verboseOutput);
136136

137137
/** Runs a tool and provides common boilerplate code.
138138
@@ -193,8 +193,8 @@ interface Compiler {
193193
format("Failed to invoke the compiler %s to determine the build platform: %s",
194194
compiler_binary, result.output));
195195
BuildPlatform build_platform = readPlatformSDLProbe(result.output);
196-
string ver = determineVersion(compiler_binary, result.output).strip;
197196
build_platform.compilerBinary = compiler_binary;
197+
string ver = determineVersion(build_platform, result.output).strip;
198198

199199
if (ver.empty) {
200200
logWarn(`Could not probe the compiler version for "%s". ` ~

source/dub/compilers/dmd.d

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,29 @@ config /etc/dmd.conf
9999
assert(c && c.length > 1 && c[1] == "2.084.0-beta.1");
100100
}
101101

102-
string determineVersion(string compiler_binary, string verboseOutput)
102+
string determineVersion(in BuildPlatform platform, string verboseOutput)
103103
{
104-
import std.regex : matchFirst, regex;
105-
auto ver = matchFirst(verboseOutput, regex(dmdVersionRe, "m"));
106-
return ver && ver.length > 1 ? ver[1] : null;
104+
// Find the backend version of the compiler, not the dmd FE.
105+
// Specificically, for gdmd-14 this function should return
106+
// 14.X.Y not 2.108.Z
107+
switch (platform.compiler) {
108+
case "dmd":
109+
case "ldc":
110+
{
111+
import std.regex : matchFirst, regex;
112+
auto ver = matchFirst(verboseOutput, regex(dmdVersionRe, "m"));
113+
return ver && ver.length > 1 ? ver[1] : null;
114+
}
115+
case "gdc":
116+
{
117+
import std.process;
118+
const result = execute([platform.compilerBinary, "-q,-dumpfullversion", "--version"]);
119+
return result.status == 0 ? result.output : null;
120+
}
121+
default:
122+
throw new UnknownCompilerException(platform.compiler);
123+
}
124+
107125
}
108126

109127
BuildPlatform determinePlatform(ref BuildSettings settings, string compiler_binary, string arch_override)

source/dub/compilers/gdc.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ class GDCCompiler : Compiler {
5454

5555
@property string name() const { return "gdc"; }
5656

57-
string determineVersion(string compiler_binary, string verboseOutput)
57+
string determineVersion(in BuildPlatform platform, string verboseOutput)
5858
{
5959
const result = execute([
60-
compiler_binary,
60+
platform.compilerBinary,
6161
"-dumpfullversion",
6262
"-dumpversion"
6363
]);

source/dub/compilers/ldc.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
6969
assert(c && c.length > 1 && c[1] == "1.11.0");
7070
}
7171

72-
string determineVersion(string compiler_binary, string verboseOutput)
72+
string determineVersion(in BuildPlatform platform, string verboseOutput)
7373
{
7474
import std.regex : matchFirst, regex;
7575
auto ver = matchFirst(verboseOutput, regex(ldcVersionRe, "m"));

0 commit comments

Comments
 (0)