Skip to content

Commit

Permalink
v2.12.3 Resolved #608
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Bothe committed May 8, 2015
1 parent a72514f commit 054a536
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 5 deletions.
2 changes: 1 addition & 1 deletion MonoDevelop.DBinding/MonoDevelop.D.addin.xml
Expand Up @@ -6,7 +6,7 @@
copyright=""
description="D Language Binding"
category="Language bindings"
version="2.12.2">
version="2.12.3">

<!-- Resources -->

Expand Down
105 changes: 102 additions & 3 deletions MonoDevelop.DBinding/Projects/Dub/DubReferencesCollection.cs
Expand Up @@ -199,15 +199,114 @@ bool TryInterpretDubListOutput(string outp)
{
ret = true;
if (match.Success && dependencies.TryGetValue(match.Groups["name"].Value, out dep) &&
//(string.IsNullOrEmpty(dep.Version) || dep.Version == match.Groups["version"].Value) && // TODO: Appropriate handling of dep versions
string.IsNullOrEmpty(dep.Path)/* &&
!dep.Name.Contains(":")*/) // Since dub v0.9.20, subpackages' paths are included in the path list as well!
string.IsNullOrEmpty(dep.Path) &&
(string.IsNullOrEmpty(dep.Version) || CheckRequiredDepVersion(dep.Version, match.Groups["version"].Value))
/* && !dep.Name.Contains(":") */) // Since dub v0.9.20, subpackages' paths are included in the path list as well!
dep.Path = match.Groups["path"].Value.Trim();

}
return ret;
}

static Regex SemVerRegex = new Regex (
@"(?<op>~>|==|>=|<=)?"+
@"(?<maj>0|[1-9][0-9]*)"+
@"(\.(?<min>0|[1-9][0-9]*))?"+
@"(\.(?<bug>0|[1-9][0-9]*))?"+
@"(?<prerelease>-[\da-z\-]+(?:\.[\da-z\-]+)*)?"+
@"(?<build>\+[\da-z\-]+(?:\.[\da-z\-]+)*)?", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.ExplicitCapture);


static bool CheckRequiredDepVersion(string expectedVersion, string actualVersion)
{
var expectedVer = SemVerRegex.Match (expectedVersion);
var actualVer = SemVerRegex.Match (actualVersion);

// Discard invalid/obsolete stuff/*
if (!expectedVer.Success || !actualVer.Success)
return true;

// also discard explicit version ranges like ">=1.3.0 <=1.3.4" for now...who uses this?
var cmp = CompareVersions(expectedVer, actualVer);

switch (expectedVer.Groups ["op"].Value ?? string.Empty) {
case "~>":
if (cmp == 0)
return true;

if (cmp > 0) {
int maj_expected, maj_actual;
int min_expected, min_actual;
int bug_expected, bug_actual;

int.TryParse (expectedVer.Groups ["maj"].Value, out maj_expected);
int.TryParse (actualVer.Groups ["maj"].Value, out maj_actual);
int.TryParse (expectedVer.Groups ["min"].Value, out min_expected);
int.TryParse (actualVer.Groups ["min"].Value, out min_actual);
int.TryParse (expectedVer.Groups ["bug"].Value, out bug_expected);
int.TryParse (actualVer.Groups ["bug"].Value, out bug_actual);

if (bug_expected != 0)
return maj_actual == maj_expected && min_actual - min_expected <= 1;
if (min_expected != 0)
return maj_actual - maj_expected <= 1;
}
return false;
case ">=":
return cmp >= 0;
case "<=":
return cmp <= 0;
case "":
case "==":
return cmp == 0;
}

return true;
}

/// <summary>
/// Compares the versions.
/// </summary>
/// <returns>
/// greater 0 if actual greater than expected;
/// 0 if expected equals actual;
/// less 0 if actual less than expected</returns>
static int CompareVersions(Match expectedVer, Match actualVer)
{
int maj_expected, maj_actual;
int min_expected, min_actual;
int bug_expected, bug_actual;

int.TryParse (expectedVer.Groups ["maj"].Value, out maj_expected);
int.TryParse (actualVer.Groups ["maj"].Value, out maj_actual);
int.TryParse (expectedVer.Groups ["min"].Value, out min_expected);
int.TryParse (actualVer.Groups ["min"].Value, out min_actual);
int.TryParse (expectedVer.Groups ["bug"].Value, out bug_expected);
int.TryParse (actualVer.Groups ["bug"].Value, out bug_actual);

if (maj_expected != maj_actual)
return maj_actual - maj_expected;

if (min_expected != min_actual)
return min_actual - min_expected;

if (bug_expected != bug_actual)
return bug_actual - bug_expected;

var prerelease_expected = expectedVer.Groups ["prerelease"].Value;
var prerelease_actual = actualVer.Groups ["prerelease"].Value;

// Prefer non-prerelease versions
var prerelease = // 1 == only expectedVersion has prerelease; -1 == only actualVersion has prerelease; 0 == both or none have prerelease.
(string.IsNullOrWhiteSpace(prerelease_expected) ? 0 : 1) -
(string.IsNullOrWhiteSpace(prerelease_actual) ? 0 : 1);
if (prerelease != 0 && !string.IsNullOrWhiteSpace (prerelease_expected))
return prerelease;

// Don't sort lexicographically for now and discard further checks..
return 0;
}

public IEnumerator<DubProjectDependency> GetEnumerator()
{
return dependencies.Values.GetEnumerator();
Expand Down
2 changes: 1 addition & 1 deletion Parser

0 comments on commit 054a536

Please sign in to comment.