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

Do dependency resolution after checking valid configs #2960

Merged
merged 3 commits into from
Sep 24, 2024
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
24 changes: 19 additions & 5 deletions source/dub/dependencyresolver.d
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ class DependencyResolver(CONFIGS, CONFIG) {
ulong loop_counter = this.loop_limit;
constrain(root, context, loop_counter);

// Get best available results
foreach (base; context.configs.keys)
foreach (j, ref sc; context.configs[base])
if (sc.included){
context.result[base] = sc.config;
break;
}

// remove any non-default optional dependencies
purgeOptionalDependencies(root, context.result);

Expand Down Expand Up @@ -176,9 +184,6 @@ class DependencyResolver(CONFIGS, CONFIG) {
assert(base in context.configs);
if (context.isVisited(n.pack)) return;
context.setVisited(n.pack);
context.result[base] = n.config;
foreach (j, ref sc; context.configs[base])
sc.included = sc.config == n.config;

auto dependencies = getChildren(n);

Expand Down Expand Up @@ -316,10 +321,19 @@ class DependencyResolver(CONFIGS, CONFIG) {

auto failbase = failedNode.main;

// Get partial results
CONFIG[PackageName] partial_result;
foreach (base; context.configs.keys)
foreach (j, ref sc; context.configs[base])
if (sc.included){
partial_result[base] = sc.config;
break;
}

// get the list of all dependencies to the failed package
auto deps = context.visited.byKey
.filter!(p => !!(p.main in context.result))
.map!(p => TreeNode(p, context.result[p.main]))
.filter!(p => !!(p.main in partial_result))
.map!(p => TreeNode(p, partial_result[p.main]))
.map!(n => getChildren(n)
.filter!(d => d.pack.main == failbase)
.map!(d => tuple(n, d))
Expand Down
48 changes: 48 additions & 0 deletions source/dub/test/dependencies.d
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,51 @@ version "1.0.0"`, PackageFormat.sdl);
assert(dub.project.getDependency("b", true), "Missing 'b' dependency");
assert(dub.project.getDependency("no", true) is null, "Returned unexpected dependency");
}

// Issue 2695 - Nonsensical dependencies
// Dependencies should resolve versions correctly regardless of the order they get requested
unittest
{
scope dub = new TestDub((scope Filesystem root) {
root.writeFile(TestDub.ProjectPath ~ "dub.sdl", `name "main"
dependency "a" version="*"
dependency "b" version="*"`);
root.writePackageFile("a", "0.0.0", `name "a"
dependency "c" version="~>0.0.0"`, PackageFormat.sdl);
root.writePackageFile("b", "0.0.0", `name "b"
dependency "c" version="0.0.0"`, PackageFormat.sdl);
root.writePackageFile("c", "0.0.0", `name "c"
version "0.0.0"`, PackageFormat.sdl);
root.writePackageFile("c", "0.0.1", `name "c"
version "0.0.1"`, PackageFormat.sdl);
});
dub.loadPackage();

dub.upgrade(UpgradeOptions.select);

assert(dub.project.hasAllDependencies(), "project have missing dependencies");
assert(dub.project.getDependency("c", true).version_ == Version("0.0.0"));
}

unittest
{
scope dub = new TestDub((scope Filesystem root) {
root.writeFile(TestDub.ProjectPath ~ "dub.sdl", `name "main"
dependency "a" version="*"
dependency "b" version="*"`);
root.writePackageFile("a", "1.0.0", `name "a"
dependency "c" version="0.0.0"`, PackageFormat.sdl);
root.writePackageFile("b", "1.0.0", `name "b"
dependency "c" version="~>0.0.0"`, PackageFormat.sdl);
root.writePackageFile("c", "0.0.0", `name "c"
version "0.0.0"`, PackageFormat.sdl);
root.writePackageFile("c", "0.0.1", `name "c"
version "0.0.1"`, PackageFormat.sdl);
});
dub.loadPackage();

dub.upgrade(UpgradeOptions.select);

assert(dub.project.hasAllDependencies(), "project have missing dependencies");
assert(dub.project.getDependency("c", true).version_ == Version("0.0.0"));
}
Loading