diff --git a/source/dub/compilers/compiler.d b/source/dub/compilers/compiler.d index b6a96cc..42e6cf9 100644 --- a/source/dub/compilers/compiler.d +++ b/source/dub/compilers/compiler.d @@ -92,6 +92,9 @@ /// Convert linker flags to compiler format string[] lflagsToDFlags(in string[] lflags) const; + /// Determines compiler version + string determineVersion(string compiler_binary, string verboseOutput); + /** Runs a tool and provides common boilerplate code. This method should be used by `Compiler` implementations to invoke the @@ -123,19 +126,12 @@ compiler_binary = binary to invoke compiler with args = arguments for the probe compilation arch_override = special handler for x86_mscoff - versionRes = array of regular expressions to scan the output - and find the compiler version. For each, the - version must be in capture index 1. The output - is scanned in multi-line mode (i.e. ^ will match any line start) */ protected final BuildPlatform probePlatform(string compiler_binary, string[] args, - string arch_override, string[] versionRes) + string arch_override) { import dub.compilers.utils : generatePlatformProbeFile, readPlatformJsonProbe; - import std.algorithm : filter, map; - import std.range : takeOne; - import std.regex : matchFirst, regex; - import std.string : format; + import std.string : format, strip; auto fil = generatePlatformProbeFile(); @@ -151,17 +147,14 @@ `This will probably result in build errors.`, build_platform.compiler, this.name); } - auto ver = versionRes - .map!(re => matchFirst(result.output, regex(re, "m"))) - .filter!(c => c.length > 1) - .map!(c => c[1]) - .takeOne(); + auto ver = determineVersion(compiler_binary, result.output) + .strip; if (ver.empty) { logWarn(`Could not probe the compiler version for "%s". ` ~ `Toolchain requirements might be ineffective`, build_platform.compiler); } else { - build_platform.compilerVersion = ver.front; + build_platform.compilerVersion = ver; } // Hack: see #1059 diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index a628076..2429f8c 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -99,6 +99,13 @@ assert(c && c.length > 1 && c[1] == "2.084.0-beta.1"); } + string determineVersion(string compiler_binary, string verboseOutput) + { + import std.regex : matchFirst, regex; + auto ver = matchFirst(verboseOutput, regex(dmdVersionRe, "m")); + return ver && ver.length > 1 ? ver[1] : null; + } + BuildPlatform determinePlatform(ref BuildSettings settings, string compiler_binary, string arch_override) { string[] arch_flags; @@ -121,8 +128,7 @@ return probePlatform( compiler_binary, arch_flags ~ ["-quiet", "-c", "-o-", "-v"], - arch_override, - [ dmdVersionRe ] + arch_override ); } diff --git a/source/dub/compilers/gdc.d b/source/dub/compilers/gdc.d index 53225e3..30e07f5 100644 --- a/source/dub/compilers/gdc.d +++ b/source/dub/compilers/gdc.d @@ -54,31 +54,15 @@ @property string name() const { return "gdc"; } - enum gdcVersionRe1 = `GDC\s+(\d+\.\d+\.\d+[A-Za-z0-9.+-]*)`; - enum gdcVersionRe2 = `^GNU D \(.*?\) version (\d+\.\d+\.\d+[A-Za-z0-9.+-]*)`; - enum gdcVersionRe3 = `^gcc version (\d+\.\d+\.\d+[A-Za-z0-9.+-]*)`; + string determineVersion(string compiler_binary, string verboseOutput) + { + const result = execute([ + compiler_binary, + "-dumpfullversion", + "-dumpversion" + ]); - unittest { - import std.algorithm : equal, map; - import std.range : only; - import std.regex : matchFirst, regex; - auto probe = ` -Target: x86_64-pc-linux-gnu -Thread model: posix -gcc version 8.2.1 20180831 (GDC 8.2.1 based on D v2.068.2 built with ISL 0.20 for Arch Linux) -GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 -GNU D (GDC 8.2.1 based on D v2.068.2 built with ISL 0.20 for Arch Linux) version 8.2.1 20180831 (x86_64-pc-linux-gnu) -GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 -binary /usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/cc1d -version v2.068.2 -predefs GNU D_Version2 LittleEndian GNU_DWARF2_Exceptions GNU_StackGrowsDown GNU_InlineAsm D_LP64 D_PIC assert all X86_64 D_HardFloat Posix linux CRuntime_Glibc -`; - auto vers = only(gdcVersionRe1, gdcVersionRe2, gdcVersionRe3) - .map!(re => matchFirst(probe, regex(re, "m"))) - .filter!(c => c && c.length > 1) - .map!(c => c[1]); - - assert(vers.equal([ "8.2.1", "8.2.1", "8.2.1" ])); + return result.status == 0 ? result.output : null; } BuildPlatform determinePlatform(ref BuildSettings settings, string compiler_binary, string arch_override) @@ -97,8 +81,7 @@ return probePlatform( compiler_binary, arch_flags ~ ["-S", "-v"], - arch_override, - [ gdcVersionRe1, gdcVersionRe2, gdcVersionRe3 ] + arch_override ); } diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index 4522825..c263bea 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -69,6 +69,13 @@ assert(c && c.length > 1 && c[1] == "1.11.0"); } + string determineVersion(string compiler_binary, string verboseOutput) + { + import std.regex : matchFirst, regex; + auto ver = matchFirst(verboseOutput, regex(ldcVersionRe, "m")); + return ver && ver.length > 1 ? ver[1] : null; + } + BuildPlatform determinePlatform(ref BuildSettings settings, string compiler_binary, string arch_override) { string[] arch_flags; @@ -83,8 +90,7 @@ return probePlatform( compiler_binary, arch_flags ~ ["-c", "-o-", "-v"], - arch_override, - [ ldcVersionRe ] + arch_override ); }