diff --git a/changelog/minDubVersion.dd b/changelog/minDubVersion.dd new file mode 100644 index 0000000..79d91f0 --- /dev/null +++ b/changelog/minDubVersion.dd @@ -0,0 +1,17 @@ +Dub now supports a `minDubVersion` field. + +This field will abort the build if the user doesn't have a recent enough version of dub +and miss needed feature to perform the build. + +`minDubVersion` can be added to project's `dub.json`: +------- +{ + ... + "minDubVersion": "1.10" + ... +} +------ +or `dub.sdl`: +------ +minDubVersion "1.10" +------ diff --git a/source/dub/package_.d b/source/dub/package_.d index bac7020..089f179 100644 --- a/source/dub/package_.d +++ b/source/dub/package_.d @@ -116,6 +116,7 @@ // use the given recipe as the basis m_info = recipe; + checkMinDubVersion(); fillWithDefaults(); } @@ -619,6 +620,35 @@ return ret; } + private void checkMinDubVersion() + { + import dub.semver : compareVersions, expandVersion, isValidVersion; + import dub.version_ : dubVersion; + import std.exception : enforce; + + if (m_info.minDubVersion.length) { + auto mdv = m_info.minDubVersion; + if (!isValidVersion(mdv)) { + mdv = expandVersion(mdv); + enforce(isValidVersion(mdv), + "minDubVersion "~m_info.minDubVersion~" is not SemVer compliant!"); + } + + static assert(dubVersion.length); + static if (dubVersion[0] == 'v') { + enum dv = dubVersion[1 .. $]; + } + else { + enum dv = dubVersion; + } + static assert(isValidVersion(dv)); + + enforce(compareVersions(dv, mdv) >= 0, + "dub-"~dv~" does not comply with minDubVersion specification: "~mdv~ + ".\nPlease consider upgrading your dub installation."); + } + } + private void fillWithDefaults() { auto bs = &m_info.buildSettings; diff --git a/source/dub/recipe/json.d b/source/dub/recipe/json.d index a254e89..707facb 100644 --- a/source/dub/recipe/json.d +++ b/source/dub/recipe/json.d @@ -33,6 +33,7 @@ case "authors": recipe.authors = deserializeJson!(string[])(value); break; case "copyright": recipe.copyright = value.get!string; break; case "license": recipe.license = value.get!string; break; + case "minDubVersion": recipe.minDubVersion = value.get!string; break; case "configurations": break; // handled below, after the global settings have been parsed case "buildTypes": foreach (string name, settings; value) { @@ -80,6 +81,7 @@ if (!recipe.authors.empty) ret["authors"] = serializeToJson(recipe.authors); if (!recipe.copyright.empty) ret["copyright"] = recipe.copyright; if (!recipe.license.empty) ret["license"] = recipe.license; + if (!recipe.minDubVersion.empty) ret["minDubVersion"] = recipe.minDubVersion; if (!recipe.subPackages.empty) { Json[] jsonSubPackages = new Json[recipe.subPackages.length]; foreach (i, subPackage; recipe.subPackages) { diff --git a/source/dub/recipe/packagerecipe.d b/source/dub/recipe/packagerecipe.d index 7775bdb..b323bc5 100644 --- a/source/dub/recipe/packagerecipe.d +++ b/source/dub/recipe/packagerecipe.d @@ -79,6 +79,7 @@ string[] authors; string copyright; string license; + string minDubVersion; string[] ddoxFilterArgs; string ddoxTool; BuildSettingsTemplate buildSettings; diff --git a/source/dub/recipe/sdl.d b/source/dub/recipe/sdl.d index 33dc59d..dfabb45 100644 --- a/source/dub/recipe/sdl.d +++ b/source/dub/recipe/sdl.d @@ -42,6 +42,7 @@ case "authors": recipe.authors ~= n.stringArrayTagValue; break; case "copyright": recipe.copyright = n.stringTagValue; break; case "license": recipe.license = n.stringTagValue; break; + case "minDubVersion": recipe.minDubVersion = n.stringTagValue; break; case "subPackage": subpacks ~= n; break; case "configuration": configs ~= n; break; case "buildType": @@ -96,6 +97,7 @@ if (recipe.authors.length) ret.add(new Tag(null, "authors", recipe.authors.map!(a => Value(a)).array)); if (recipe.copyright.length) add("copyright", recipe.copyright); if (recipe.license.length) add("license", recipe.license); + if (recipe.minDubVersion.length) add("minDubVersion", recipe.minDubVersion); foreach (name, settings; recipe.buildTypes) { auto t = new Tag(null, "buildType", [Value(name)]); t.add(settings.toSDL()); diff --git a/test/issue1531-min-dub-version.sh b/test/issue1531-min-dub-version.sh new file mode 100755 index 0000000..7fc1230 --- /dev/null +++ b/test/issue1531-min-dub-version.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -e + +. $(dirname "${BASH_SOURCE[0]}")/common.sh + +cat << EOF | $DUB - || die "Did not pass minDubVersion \"1.0\"" +/+ dub.sdl: + minDubVersion "1.0" ++/ +void main() {} +EOF + +! cat << EOF | $DUB - || die "Did pass minDubVersion \"99.0\"" +/+ dub.sdl: + minDubVersion "99.0" ++/ +void main() {} +EOF