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

Fix #2706: Dub run ignores locally registered packages #2787

Merged
merged 1 commit into from
Jan 9, 2024
Merged
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
62 changes: 30 additions & 32 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,6 @@ class BuildCommand : GenerateCommand {

private int fetchMissingPackages(Dub dub, in UserPackageDesc packageParts)
{

static bool input(string caption, bool default_value = true) {
writef("%s [%s]: ", caption, default_value ? "Y/n" : "y/N");
auto inp = readln();
Expand All @@ -1554,42 +1553,41 @@ class BuildCommand : GenerateCommand {
}
}

VersionRange dep;

if (packageParts.range != VersionRange.Any) {
// the user provided a version manually
dep = packageParts.range;
} else if (packageParts.name.startsWith(":")) {
// Sub-packages are always assumed to be present
return 0;
} else if (dub.packageManager.getBestPackage(packageParts.name)) {
// found locally
// Local subpackages are always assumed to be present
if (packageParts.name.startsWith(":"))
return 0;
} else {
// search for the package and filter versions for exact matches
auto basePackageName = getBasePackageName(packageParts.name);
auto search = dub.searchPackages(basePackageName)
.map!(tup => tup[1].find!(p => p.name == basePackageName))
.filter!(ps => !ps.empty);
if (search.empty) {
logWarn("Package '%s' was neither found locally nor online.", packageParts.name);
return 2;
}

const p = search.front.front;
logInfo("Package '%s' was not found locally but is available online:", packageParts.name);
logInfo("---");
logInfo("Description: %s", p.description);
logInfo("Version: %s", p.version_);
logInfo("---");
const baseName = getBasePackageName(packageParts.name);
// Found locally
if (dub.packageManager.getBestPackage(baseName, packageParts.range))
return 0;

const answer = m_yes ? true : input("Do you want to fetch '%s' now?".format(packageParts.name));
if (!answer)
return 0;
dep = VersionRange.fromString(p.version_);
// Non-interactive, either via flag, or because a version was provided
if (m_yes || !packageParts.range.matchesAny()) {
dub.fetch(baseName, packageParts.range, dub.defaultPlacementLocation,
FetchOptions.none);
return 0;
}
// Otherwise we go the long way of asking the user.
// search for the package and filter versions for exact matches
auto search = dub.searchPackages(baseName)
.map!(tup => tup[1].find!(p => p.name == baseName))
.filter!(ps => !ps.empty);
if (search.empty) {
logWarn("Package '%s' was neither found locally nor online.", packageParts);
return 2;
}

const p = search.front.front;
logInfo("Package '%s' was not found locally but is available online:", packageParts);
logInfo("---");
logInfo("Description: %s", p.description);
logInfo("Version: %s", p.version_);
logInfo("---");

dub.fetch(packageParts.name, dep, dub.defaultPlacementLocation, FetchOptions.none);
if (input("Do you want to fetch '%s@%s' now?".format(packageParts, p.version_)))
dub.fetch(baseName, VersionRange.fromString(p.version_),
dub.defaultPlacementLocation, FetchOptions.none);
return 0;
}
}
Expand Down
Loading