diff --git a/source/dub/compilers/compiler.d b/source/dub/compilers/compiler.d index c641972..b6a96cc 100644 --- a/source/dub/compilers/compiler.d +++ b/source/dub/compilers/compiler.d @@ -92,13 +92,6 @@ /// Convert linker flags to compiler format string[] lflagsToDFlags(in string[] lflags) const; - /// Get the dependency requirement string for this compiler - Dependency toolchainRequirement(const ref ToolchainRequirements tr); - - /// Check whether the compiler meet the compiler requirement specified - /// in the recipe. - bool checkCompilerRequirement(const ref BuildPlatform platform, const ref ToolchainRequirements tr); - /** Runs a tool and provides common boilerplate code. This method should be used by `Compiler` implementations to invoke the diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index c2b10a1..ac0a459 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -265,19 +265,6 @@ return lflags.map!(f => "-L"~f)().array(); } - Dependency toolchainRequirement(const ref ToolchainRequirements tr) - { - return tr.dmd; - } - - bool checkCompilerRequirement(const ref BuildPlatform platform, const ref ToolchainRequirements tr) - { - auto ver = platform.compilerVersion.length - ? dmdLikeVersionToSemverLike(platform.compilerVersion) - : "0.0.0"; - return tr.dmd.matches(ver); - } - private auto escapeArgs(in string[] args) { return args.map!(s => s.canFind(' ') ? "\""~s~"\"" : s); diff --git a/source/dub/compilers/gdc.d b/source/dub/compilers/gdc.d index 112f756..53225e3 100644 --- a/source/dub/compilers/gdc.d +++ b/source/dub/compilers/gdc.d @@ -256,18 +256,6 @@ return dflags; } - - final Dependency toolchainRequirement(const ref ToolchainRequirements tr) - { - return tr.gdc; - } - - final bool checkCompilerRequirement(const ref BuildPlatform platform, const ref ToolchainRequirements tr) - { - auto ver = platform.compilerVersion.length - ? platform.compilerVersion : "0.0.0"; - return tr.gdc.matches(ver); - } } private string extractTarget(const string[] args) { auto i = args.countUntil("-o"); return i >= 0 ? args[i+1] : null; } diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index d3ce920..4522825 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -233,18 +233,6 @@ return lflags.map!(s => "-L="~s)().array(); } - final Dependency toolchainRequirement(const ref ToolchainRequirements tr) - { - return tr.ldc; - } - - final bool checkCompilerRequirement(const ref BuildPlatform platform, const ref ToolchainRequirements tr) - { - auto ver = platform.compilerVersion.length - ? platform.compilerVersion : "0.0.0"; - return tr.ldc.matches(ver); - } - private auto escapeArgs(in string[] args) { return args.map!(s => s.canFind(' ') ? "\""~s~"\"" : s); diff --git a/source/dub/generators/build.d b/source/dub/generators/build.d index ff4ada4..b3b239c 100644 --- a/source/dub/generators/build.d +++ b/source/dub/generators/build.d @@ -50,46 +50,13 @@ void checkPkgRequirements(const(Package) pkg) { - import std.format : format; - const tr = pkg.recipe.toolchainRequirements; - - if (dcl.toolchainRequirement(tr) == Dependency.invalid) - throw new Exception(format( - "Installed %s-%s is not supported by %s. Supported compiler(s):\n%s", - dcl.name, settings.platform.compilerVersion, pkg.name, - tr.supportedCompilers.map!((cs) { - auto str = " - " ~ cs[0]; - if (cs[1] != Dependency.any) str ~= ": " ~ cs[1].toString(); - return str; - }).join("\n") - )); - - enforce( - dcl.checkCompilerRequirement(settings.platform, tr), - format( - "Installed %s-%s does not comply with %s compiler requirement: %s %s\n" ~ - "Please consider upgrading your installation.", - dcl.name, settings.platform.compilerVersion, - pkg.name, dcl.name, dcl.toolchainRequirement(tr) - ) - ); - - enforce( - tr.matchesFrontendVersion(settings.platform), - format( - "Installed %s-%s with frontend %s does not comply with %s frontend requirement: %s\n" ~ - "Please consider upgrading your installation.", - dcl.name, settings.platform.compilerVersion, - settings.platform.frontendVersionString, pkg.name, tr.frontend - ) - ); + tr.checkPlatform(settings.platform, pkg.name); } checkPkgRequirements(m_project.rootPackage); - foreach (pkg; m_project.dependencies) { + foreach (pkg; m_project.dependencies) checkPkgRequirements(pkg); - } auto root_ti = targets[m_project.rootPackage.name]; diff --git a/source/dub/recipe/packagerecipe.d b/source/dub/recipe/packagerecipe.d index 0c5962c..5a73030 100644 --- a/source/dub/recipe/packagerecipe.d +++ b/source/dub/recipe/packagerecipe.d @@ -145,12 +145,6 @@ return only(dub, frontend, dmd, ldc, gdc) .all!(r => r == Dependency.any); } - - bool matchesFrontendVersion(in ref BuildPlatform platform) - const { - import dub.compilers.utils : dmdLikeVersionToSemverLike; - return frontend.matches(Version(dmdLikeVersionToSemverLike(platform.frontendVersionString))); - } } @@ -336,6 +330,69 @@ } } +package(dub) void checkPlatform(in ref ToolchainRequirements tr, BuildPlatform platform, string package_name) +{ + import dub.compilers.utils : dmdLikeVersionToSemverLike; + import std.algorithm.iteration : map; + import std.format : format; + + string compilerver; + Dependency compilerspec; + + switch (platform.compiler) { + default: + compilerspec = Dependency.any; + compilerver = "0.0.0"; + break; + case "dmd": + compilerspec = tr.dmd; + compilerver = platform.compilerVersion.length + ? dmdLikeVersionToSemverLike(platform.compilerVersion) + : "0.0.0"; + break; + case "ldc": + compilerspec = tr.ldc; + compilerver = platform.compilerVersion; + if (!compilerver.length) compilerver = "0.0.0"; + break; + case "gdc": + compilerspec = tr.gdc; + compilerver = platform.compilerVersion; + if (!compilerver.length) compilerver = "0.0.0"; + break; + } + + enforce(compilerspec != Dependency.invalid, + format( + "Installed %s %s is not supported by %s. Supported compiler(s):\n%s", + platform.compiler, platform.compilerVersion, package_name, + tr.supportedCompilers.map!((cs) { + auto str = " - " ~ cs[0]; + if (cs[1] != Dependency.any) str ~= ": " ~ cs[1].toString(); + return str; + }).join("\n") + ) + ); + + enforce(compilerspec.matches(compilerver), + format( + "Installed %s-%s does not comply with %s compiler requirement: %s %s\n" ~ + "Please consider upgrading your installation.", + platform.compiler, platform.compilerVersion, + package_name, platform.compiler, compilerspec + ) + ); + + enforce(tr.frontend.matches(dmdLikeVersionToSemverLike(platform.frontendVersionString)), + format( + "Installed %s-%s with frontend %s does not comply with %s frontend requirement: %s\n" ~ + "Please consider upgrading your installation.", + platform.compiler, platform.compilerVersion, + platform.frontendVersionString, package_name, tr.frontend + ) + ); +} + package bool addRequirement(ref ToolchainRequirements req, string name, string value) { switch (name) {