Skip to content

Commit

Permalink
implement minDubVersion check
Browse files Browse the repository at this point in the history
fix #1531
  • Loading branch information
rtbo committed Aug 18, 2018
1 parent 520d527 commit db5b906
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions source/dub/package_.d
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Package {
// use the given recipe as the basis
m_info = recipe;

checkMinDubVersion();
fillWithDefaults();
}

Expand Down Expand Up @@ -619,6 +620,32 @@ class Package {
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);
}
}

private void fillWithDefaults()
{
auto bs = &m_info.buildSettings;
Expand Down
2 changes: 2 additions & 0 deletions source/dub/recipe/json.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void parseJson(ref PackageRecipe recipe, Json json, string parent_name)
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) {
Expand Down Expand Up @@ -80,6 +81,7 @@ Json toJson(in ref PackageRecipe recipe)
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) {
Expand Down
1 change: 1 addition & 0 deletions source/dub/recipe/packagerecipe.d
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct PackageRecipe {
string[] authors;
string copyright;
string license;
string minDubVersion;
string[] ddoxFilterArgs;
string ddoxTool;
BuildSettingsTemplate buildSettings;
Expand Down
2 changes: 2 additions & 0 deletions source/dub/recipe/sdl.d
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void parseSDL(ref PackageRecipe recipe, Tag sdl, string parent_name)
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":
Expand Down Expand Up @@ -96,6 +97,7 @@ Tag toSDL(in ref PackageRecipe recipe)
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());
Expand Down

0 comments on commit db5b906

Please sign in to comment.