Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PackageManager.getBestPackage: Introduce Version[Range] overloads #2375

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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