Match versions of cached packages exactly.
Uses exact version matching instead of SemVer matching for cached packages to enforce exact matches for SCM based dependencies in particular.
1 parent 98dd507 commit 0c6361099fc3e6cb80d1244e1f4d21d8597b420a
@Sönke Ludwig Sönke Ludwig authored on 4 Jul 2022
Showing 2 changed files
View
23
source/dub/dependency.d
 
/// 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
has precedence over other branches. Apart from that, versions are
int opCmp(const Version other) const { return opCmp(other); }
 
/// Returns the string representation of the version/branch.
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;
 
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.
bool isGitHash(string hash) @nogc nothrow pure @safe
View
2
■■■
source/dub/packagemanager.d
}
}
 
foreach (p; getPackageIterator(name))
if (p.version_ == ver)
if (p.version_.matches(ver, isManagedPackage(p) ? VersionMatchMode.strict : VersionMatchMode.standard))
return p;
 
return null;
}