Skip to content

Commit

Permalink
PackageManager.getBestPackage: Introduce Version[Range] overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Geod24 authored and WebFreak001 committed Aug 11, 2022
1 parent 7704bbc commit 01bab5e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -1116,8 +1116,8 @@ abstract class PackageBuildCommand : Command {

enforce(package_name.length, "No valid root package found - aborting.");

auto pack = dub.packageManager.getBestPackage(
package_name, ver.length ? Dependency(ver) : Dependency.any);
const vers = ver.length ? VersionRange.fromString(ver) : VersionRange.Any;
auto pack = dub.packageManager.getBestPackage(package_name, vers);

enforce(pack, format!"Failed to find a package named '%s%s' locally."(package_name,
ver == "" ? "" : ("@" ~ ver)
Expand Down
4 changes: 2 additions & 2 deletions source/dub/dub.d
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ class Dub {

auto tool = "dscanner";

auto tool_pack = m_packageManager.getBestPackage(tool, ">=0.0.0");
auto tool_pack = m_packageManager.getBestPackage(tool);
if (!tool_pack) tool_pack = m_packageManager.getBestPackage(tool, "~master");
if (!tool_pack) {
logInfo("Hint", Color.light_blue, "%s is not present, getting and storing it user wide", tool);
Expand Down Expand Up @@ -1155,7 +1155,7 @@ class Dub {
private void runCustomInitialization(NativePath path, string type, string[] runArgs)
{
string packageName = type;
auto template_pack = m_packageManager.getBestPackage(packageName, ">=0.0.0");
auto template_pack = m_packageManager.getBestPackage(packageName);
if (!template_pack) template_pack = m_packageManager.getBestPackage(packageName, "~master");
if (!template_pack) {
logInfo("%s is not present, getting and storing it user wide", packageName);
Expand Down
12 changes: 12 additions & 0 deletions source/dub/packagemanager.d
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,18 @@ class PackageManager {

/** Searches for the latest version of a package matching the given dependency.
*/
Package getBestPackage(string name, VersionRange range = VersionRange.Any)
{
return this.getBestPackage(name, Dependency(range));
}

/// Ditto
Package getBestPackage(string name, Version vers)
{
return this.getBestPackage(name, VersionRange(vers, vers));
}

/// Ditto
Package getBestPackage(string name, Dependency version_spec, bool enable_overrides = true)
{
Package ret;
Expand Down
2 changes: 1 addition & 1 deletion source/dub/project.d
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ shared static this() {
return resolveSubPackage(tmp, subname, true);
},
(VersionRange range) {
return m_packageManager.getBestPackage(dep.name, vspec);
return m_packageManager.getBestPackage(dep.name, range);
},
);
} else if (m_dependencies.canFind!(d => getBasePackageName(d.name) == basename)) {
Expand Down

0 comments on commit 01bab5e

Please sign in to comment.