diff --git a/source/dub/dependency.d b/source/dub/dependency.d index 52dc3ee..6ff7dbd 100644 --- a/source/dub/dependency.d +++ b/source/dub/dependency.d @@ -863,6 +863,19 @@ /// Tests if this represents the special unknown version constant. @property bool isUnknown() const { return m_version == UNKNOWN_VERS; } + /** Tests two versions for equality, according to the selected match mode. + */ + bool matches(Version other, VersionMatchMode mode = VersionMatchMode.standard) + const { + if (this != other) + return false; + + if (mode == VersionMatchMode.strict && this.toString() != other.toString()) + return false; + + return true; + } + /** Compares two versions/branches for precedence. Versions generally have precedence over branches and the master branch @@ -900,6 +913,11 @@ string toString() const { return m_version; } } +enum VersionMatchMode { + standard, /// Match according to SemVer rules + strict /// Also include build metadata suffix in the comparison +} + unittest { Version a, b; @@ -965,6 +983,11 @@ assert(Version("1.0.0+a") == Version("1.0.0+b")); assert(Version("73535568b79a0b124bc1653002637a830ce0fcb8").isSCM); + + assert(Version("1.0.0").matches(Version("1.0.0+foo"))); + assert(Version("1.0.0").matches(Version("1.0.0+foo"), VersionMatchMode.standard)); + assert(!Version("1.0.0").matches(Version("1.0.0+foo"), VersionMatchMode.strict)); + assert(Version("1.0.0+foo").matches(Version("1.0.0+foo"), VersionMatchMode.strict)); } /// Determines whether the given string is a Git hash. diff --git a/source/dub/packagemanager.d b/source/dub/packagemanager.d index cb637bd..c0a9533 100644 --- a/source/dub/packagemanager.d +++ b/source/dub/packagemanager.d @@ -173,7 +173,7 @@ } foreach (p; getPackageIterator(name)) - if (p.version_ == ver) + if (p.version_.matches(ver, isManagedPackage(p) ? VersionMatchMode.strict : VersionMatchMode.standard)) return p; return null;