Verified Commit 391f79c1 authored by Karel Koci's avatar Karel Koci 🤘

Dependency calculations with all candidates

Adds support for candidates. Currently it can be limited only by
version. Limiting by repository isn't supported yet.
parent 8095f629
......@@ -340,10 +340,9 @@ function pkg_aggregate()
-- Canonize dependencies
modifier.deps = deps_canon(modifier.deps)
for _, candidate in ipairs(pkg_group.candidates or {}) do
candidate.deps = deps_canon(candidate.deps) or {} -- deps from updater configuration file
for _, d in ipairs(candidate.Depends or {}) do -- Depends from repository
table.insert(candidate.deps, deps_canon(d))
end
local candidate_deps = { candidate.deps } -- deps from updater configuration file
table.insert(candidate_deps, candidate.Depends) -- Depends from repository)
candidate.deps = deps_canon(candidate_deps)
end
pkg_group.modifier = modifier
-- We merged them together, they are no longer needed separately
......
This diff is collapsed.
......@@ -33,7 +33,7 @@ dependencies.
function test_no_deps()
local pkgs = {
pkg1 = {
candidates = {{Package = 'pkg1', deps = {}, repo = def_repo}},
candidates = {{Package = 'pkg1', repo = def_repo}},
modifier = {}
},
pkg2 = {
......@@ -62,7 +62,7 @@ function test_no_deps()
local expected = {
pkg1 = {
action = "require",
package = {Package = 'pkg1', deps = {}, repo = def_repo},
package = {Package = 'pkg1', repo = def_repo},
modifier = {},
name = "pkg1"
},
......@@ -175,8 +175,8 @@ function test_deps()
local pkgs = {
dep1 = {
candidates = {
{Package = 'dep1', deps = {}, Version = "1", repo = def_repo},
{Package = 'dep1', deps = {}, Version = "2", repo = def_repo}
{Package = 'dep1', Version = "2", repo = def_repo},
{Package = 'dep1', Version = "1", repo = def_repo}
},
modifier = {}
},
......@@ -197,13 +197,13 @@ function test_deps()
}
},
pkg1 = {
candidates = {{Package = 'pkg1', deps ={}, repo = def_repo}},
candidates = {{Package = 'pkg1', repo = def_repo}},
modifier = {
deps = "dep1"
}
},
pkg2 = {
candidates = {{Package = 'pkg2', deps = {'dep2', 'dep3'}, repo = def_repo}},
candidates = {{Package = 'pkg2', deps = {tp = 'dep-and', sub = {'dep2', 'dep3'}}, repo = def_repo}},
modifier = {}
}
}
......@@ -229,7 +229,7 @@ function test_deps()
local expected = {
dep1 = {
action = 'require',
package = {Package = 'dep1', deps = {}, Version = "2", repo = def_repo},
package = {Package = 'dep1', Version = "2", repo = def_repo},
modifier = {},
name = 'dep1'
},
......@@ -249,7 +249,7 @@ function test_deps()
},
pkg1 = {
action = 'require',
package = {Package = 'pkg1', deps ={}, repo = def_repo},
package = {Package = 'pkg1', repo = def_repo},
modifier = {
deps = "dep1"
},
......@@ -257,7 +257,7 @@ function test_deps()
},
pkg2 = {
action = 'require',
package = {Package = 'pkg2', deps = {'dep2', 'dep3'}, repo = def_repo},
package = {Package = 'pkg2', deps = {tp = 'dep-and', sub = {'dep2', 'dep3'}}, repo = def_repo},
modifier = {},
name = 'pkg2'
}
......@@ -271,7 +271,7 @@ A dependency doesn't exist. It should fail.
function test_missing_dep()
local pkgs = {
pkg = {
candidates = {{Package = 'pkg', deps = {'nothere'}, repo = def_repo}},
candidates = {{Package = 'pkg', deps = 'nothere', repo = def_repo}},
modifier = {}
}
}
......@@ -292,7 +292,7 @@ end
function test_circular_deps()
local pkgs = {
pkg1 = {
candidates = {{Package = 'pkg1', deps = {'pkg2'}, repo = def_repo}},
candidates = {{Package = 'pkg1', deps = 'pkg2', repo = def_repo}},
modifier = {}
},
pkg2 = {
......@@ -315,7 +315,7 @@ function test_circular_deps()
local expected = {
pkg1 = {
action = 'require',
package = {Package = 'pkg1', deps = {'pkg2'}, repo = def_repo},
package = {Package = 'pkg1', deps = 'pkg2', repo = def_repo},
modifier = {},
name = 'pkg1'
},
......@@ -339,7 +339,7 @@ end
function test_circular_deps_critical()
local pkgs = {
critic = {
candidates = {{Package = 'critic', deps = {'pkg'}, repo = def_repo}},
candidates = {{Package = 'critic', deps = 'pkg', repo = def_repo}},
modifier = { }
},
pkg = {
......@@ -727,7 +727,7 @@ function test_replan()
end
function test_candidate_choose()
local t1 = {
local candidates = {
{
Version = "1",
repo = def_repo
......@@ -739,54 +739,28 @@ function test_candidate_choose()
{
Version = "2",
repo = def_repo
}
}
assert_equal(t1[2], planner.candidate_choose(t1, "test"))
local t2 = {
{
Version = "2",
repo = {
priority = 40,
serial = 1
}
},
{
Version = "1",
repo = {
priority = 50,
serial = 2
}
}
}
assert_equal(t2[2], planner.candidate_choose(t2, "test"))
local t3 = {
{
Version = "1",
repo = {
priority = 50,
serial = 2
}
},
{
Version = "1",
repo = {
priority = 50,
serial = 1
}
}
}
assert_equal(t3[2], planner.candidate_choose(t3, "test"))
local t4 = {
{
Version = "1",
repo = def_repo
},
{
Version = "1",
Version = "4",
repo = def_repo
}
}
assert_equal(t4[1], planner.candidate_choose(t4, "test"))
assert_table_equal({
candidates[1],
candidates[3]
}, planner.candidates_choose(candidates, "<3"))
assert_table_equal({
candidates[4]
}, planner.candidates_choose(candidates, ">3"))
assert_table_equal({
candidates[2],
candidates[4]
}, planner.candidates_choose(candidates, ">=3"))
assert_table_equal({
candidates[2],
candidates[3],
candidates[4]
}, planner.candidates_choose(candidates, "=>2"))
end
function test_missing_install()
......@@ -829,7 +803,7 @@ end
function test_missing_dep_ignore()
local pkgs = {
pkg1 = {
candidates = {{Package = 'pkg1', deps = {'pkg2'}, repo = def_repo}},
candidates = {{Package = 'pkg1', deps = 'pkg2', repo = def_repo}},
modifier = {
ignore = {"deps"}
},
......@@ -850,7 +824,7 @@ function test_missing_dep_ignore()
local expected = {
{
action = "require",
package = {Package = 'pkg1', deps = {'pkg2'}, repo = def_repo},
package = {Package = 'pkg1', deps = 'pkg2', repo = def_repo},
modifier = {
ignore = {"deps"}
},
......@@ -931,6 +905,205 @@ function test_complex_deps()
assert_plan_dep_order(expected, result)
end
function test_version_request()
local pkgs = {
pkg1 = {
candidates = {
{Package = 'pkg1', deps = {}, Version = "2", repo = def_repo},
{Package = 'pkg1', deps = {}, Version = "1", repo = def_repo}
},
modifier = {}
},
pkg2 = {
candidates = {
{Package = 'pkg2', Version = "2", deps = {}, repo = def_repo},
{Package = 'pkg2', Version = "1", deps = {}, repo = def_repo}
},
modifier = {}
}
}
local requests = {
{
tp = 'install',
package = {
tp = 'package',
name = 'pkg1',
},
version = '>1'
},
{
tp = 'install',
package = {
tp = 'package',
name = 'pkg2',
},
version = '=1'
}
}
local result = planner.required_pkgs(pkgs, requests)
local expected = {
pkg1 = {
action = 'require',
package = {Package = 'pkg1', deps = {}, Version = "2", repo = def_repo},
modifier = {},
name = 'pkg1'
},
pkg2 = {
action = 'require',
package = {Package = 'pkg2', deps = {}, Version = "1", repo = def_repo},
modifier = {},
name = 'pkg2'
}
}
assert_plan_dep_order(expected, result)
end
function test_version_deps()
local pkg_dep = {
tp = 'dep-and',
sub = {
{
tp = 'dep-package',
name = 'dep1',
version = '>1'
},
{
tp = 'dep-package',
name = 'dep2',
version = '<2'
},
{
tp = 'dep-or',
sub = {
{
tp = 'dep-package',
name = 'dep3',
version = '=1'
},
{
tp = 'dep-package',
name = 'dep3',
version = '=2'
}
}
}
}
}
local pkgs = {
pkg = {
candidates = {
{Package = 'pkg', deps = pkg_dep, Version = "2", repo = def_repo},
{Package = 'pkg', deps = {}, Version = "1", repo = def_repo}
},
modifier = {}
},
dep1 = {
candidates = {
{Package = 'dep1', Version = "2", deps = {}, repo = def_repo},
{Package = 'dep1', Version = "1", deps = {}, repo = def_repo}
},
modifier = {}
},
dep2 = {
candidates = {
{Package = 'dep2', Version = "2", deps = {}, repo = def_repo},
{Package = 'dep2', Version = "1", deps = {}, repo = def_repo}
},
modifier = {}
},
dep3 = {
candidates = {
{Package = 'dep3', Version = "2", deps = {}, repo = def_repo},
{Package = 'dep3', Version = "1", deps = {}, repo = def_repo}
},
modifier = {}
}
}
local requests = {
{
tp = 'install',
package = {
tp = 'package',
name = 'pkg',
}
}
}
local result = planner.required_pkgs(pkgs, requests)
local expected = {
pkg = {
action = 'require',
package = {Package = 'pkg', deps = pkg_dep, Version = "2", repo = def_repo},
modifier = {},
name = 'pkg'
},
dep1 = {
action = 'require',
package = {Package = 'dep1', deps = {}, Version = "2", repo = def_repo},
modifier = {},
name = 'dep1'
},
dep2 = {
action = 'require',
package = {Package = 'dep2', deps = {}, Version = "1", repo = def_repo},
modifier = {},
name = 'dep2'
},
dep3 = {
action = 'require',
package = {Package = 'dep3', deps = {}, Version = "2", repo = def_repo},
modifier = {},
name = 'dep3'
}
}
assert_plan_dep_order(expected, result)
end
-- Package depends on version we don't have
function test_version_missing_dep()
local pkgs = {
pkg = {
candidates = {{Package = 'pkg', deps = {
tp = 'dep-package', name = 'dep', version = '>=2'
}, Version = "1", repo = def_repo}},
modifier = {}
},
dep = {
candidates = {{Package = 'dep', deps = {}, Version = "1", repo = def_repo}},
modifier = {}
}
}
local requests = {
{
tp = 'install',
package = {
tp = 'package',
name = 'pkg',
}
}
}
assert_exception(function () planner.required_pkgs(pkgs, requests) end, 'inconsistent')
end
function test_version_missing_request()
local pkgs = {
pkg = {
candidates = {{Package = 'pkg', Version = "1", repo = def_repo}},
modifier = {}
},
}
local requests = {
{
tp = 'install',
package = {
tp = 'package',
name = 'pkg',
},
version = '>1'
}
}
assert_exception(function () planner.required_pkgs(pkgs, requests) end, 'inconsistent')
end
function test_pkg_dep_iterate()
local dep = {
tp = "dep-and",
......
......@@ -241,13 +241,13 @@ function test_pkg_merge()
local exp = {
abc = {
candidates = {
{Package = "abc", Version = "2", deps = {}, repo = requests.known_repositories_all[1]},
{Package = "abc", Version = "1", deps = {}, repo = requests.known_repositories_all[2]}
{Package = "abc", Version = "2", repo = requests.known_repositories_all[1]},
{Package = "abc", Version = "1", repo = requests.known_repositories_all[2]}
},
modifier = {name = "abc"}
},
another = {
candidates = {{Package = "another", Version = "4", deps = {}, repo = requests.known_repositories_all[2]}},
candidates = {{Package = "another", Version = "4", repo = requests.known_repositories_all[2]}},
modifier = {name = "another"}
},
virt = {
......@@ -256,7 +256,7 @@ function test_pkg_merge()
virtual = true
},
xyz = {
candidates = {{Package = "xyz", Version = "1", deps = {}, repo = requests.known_repositories_all[1]}},
candidates = {{Package = "xyz", Version = "1", repo = requests.known_repositories_all[1]}},
modifier = {
name = "xyz",
order_after = {abc = true},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment