diff --git a/source/dub/compilers/compiler.d b/source/dub/compilers/compiler.d index d48ead6..ca4f7ac 100644 --- a/source/dub/compilers/compiler.d +++ b/source/dub/compilers/compiler.d @@ -114,6 +114,34 @@ } enforce(status == 0, format("%s failed with exit code %s.", args[0], status)); } + + /// Compiles platform probe file with the specified compiler and parses its output. + protected final BuildPlatform probePlatform(string compiler_binary, string[] args, string arch_override) + { + import std.string : format; + import dub.compilers.utils : generatePlatformProbeFile, readPlatformProbe; + + auto fil = generatePlatformProbeFile(); + + auto result = executeShell(escapeShellCommand(compiler_binary ~ args ~ fil.toNativeString())); + enforce(result.status == 0, format("Failed to invoke the compiler %s to determine the build platform: %s", + compiler_binary, result.output)); + + auto build_platform = readPlatformProbe(result.output); + build_platform.compilerBinary = compiler_binary; + + if (build_platform.compiler != this.name) { + logWarn(`The determined compiler type "%s" doesn't match the expected type "%s". This will probably result in build errors.`, + build_platform.compiler, this.name); + } + + if (arch_override.length && !build_platform.architecture.canFind(arch_override)) { + logWarn(`Failed to apply the selected architecture %s. Got %s.`, + arch_override, build_platform.architecture); + } + + return build_platform; + } } private { diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index b294330..f9aac2e 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -57,13 +57,7 @@ BuildPlatform determinePlatform(ref BuildSettings settings, string compiler_binary, string arch_override) { - import std.process; - import std.string; - - auto fil = generatePlatformProbeFile(); - string[] arch_flags; - switch (arch_override) { default: throw new Exception("Unsupported architecture: "~arch_override); case "": break; @@ -72,25 +66,7 @@ } settings.addDFlags(arch_flags); - auto result = executeShell(escapeShellCommand(compiler_binary ~ arch_flags ~ - ["-quiet", "-c", "-o-", fil.toNativeString()])); - enforce(result.status == 0, format("Failed to invoke the compiler %s to determine the build platform: %s", - compiler_binary, result.output)); - - auto build_platform = readPlatformProbe(result.output); - build_platform.compilerBinary = compiler_binary; - - if (build_platform.compiler != this.name) { - logWarn(`The determined compiler type "%s" doesn't match the expected type "%s". This will probably result in build errors.`, - build_platform.compiler, this.name); - } - - if (arch_override.length && !build_platform.architecture.canFind(arch_override)) { - logWarn(`Failed to apply the selected architecture %s. Got %s.`, - arch_override, build_platform.architecture); - } - - return build_platform; + return probePlatform(compiler_binary, arch_flags ~ ["-quiet", "-c", "-o-"], arch_override); } void prepareBuildSettings(ref BuildSettings settings, BuildSetting fields = BuildSetting.all) const diff --git a/source/dub/compilers/gdc.d b/source/dub/compilers/gdc.d index cf11e45..bb5def1 100644 --- a/source/dub/compilers/gdc.d +++ b/source/dub/compilers/gdc.d @@ -57,13 +57,7 @@ BuildPlatform determinePlatform(ref BuildSettings settings, string compiler_binary, string arch_override) { - import std.process; - import std.string; - - auto fil = generatePlatformProbeFile(); - string[] arch_flags; - switch (arch_override) { default: throw new Exception("Unsupported architecture: "~arch_override); case "": break; @@ -75,28 +69,9 @@ settings.addDFlags(arch_flags); auto binary_file = getTempFile("dub_platform_probe"); - auto result = executeShell(escapeShellCommand( - compiler_binary ~ - arch_flags ~ - ["-c", "-o", binary_file.toNativeString(), fil.toNativeString()] - )); - enforce(result.status == 0, format("Failed to invoke the compiler %s to determine the build platform: %s", - compiler_binary, result.output)); - - auto build_platform = readPlatformProbe(result.output); - build_platform.compilerBinary = compiler_binary; - - if (build_platform.compiler != this.name) { - logWarn(`The determined compiler type "%s" doesn't match the expected type "%s". This will probably result in build errors.`, - build_platform.compiler, this.name); - } - - if (arch_override.length && !build_platform.architecture.canFind(arch_override)) { - logWarn(`Failed to apply the selected architecture %s. Got %s.`, - arch_override, build_platform.architecture); - } - - return build_platform; + return probePlatform(compiler_binary, + arch_flags ~ ["-c", "-o", binary_file.toNativeString()], + arch_override); } void prepareBuildSettings(ref BuildSettings settings, BuildSetting fields = BuildSetting.all) const