Commit 75ae5115 authored by Karel Koci's avatar Karel Koci 🤘

Merge branch 'dep-alternatives' into updater-ng

parents 899d6ae6 aba9eeae
......@@ -24,6 +24,7 @@ local error = error
local type = type
local setmetatable = setmetatable
local getmetatable = getmetatable
local assert = assert
local io = io
local unpack = unpack
local events_wait = events_wait
......@@ -159,12 +160,15 @@ local error_meta = {
}
-- Generate an exception/error object. It can be further modified, of course.
function exception(reason, msg)
return setmetatable({
function exception(reason, msg, extra)
local except = {
tp = "error",
reason = reason,
msg = msg
}, error_meta)
}
assert(not(extra and (extra.tp or extra.reason or extra.msg)))
table_merge(except, extra or {})
return setmetatable(except, error_meta)
end
--[[
......
......@@ -337,16 +337,33 @@ function pkg_aggregate()
end
modifier.replan = modifier.replan or m.replan
end
-- 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
pkg_group.modifiers = nil
-- Sort candidates
if pkg_group.candidates then
table.sort(pkg_group.candidates, function(a, b)
if a.repo.priority ~= b.repo.priority then -- Check repository priority
return a.repo.priority > b.repo.priority
end
local vers_cmp = backend.version_cmp(a.Version, b.Version)
if vers_cmp ~= 0 then -- Check version of package
return vers_cmp == 1 -- a is newer version than b
end
if a.repo.serial ~= b.repo.serial then -- Check repo order of introduction
return a.repo.serial < b.repo.serial
end
WARN("Multiple candidates from same repository with same version for package " .. a.Package)
return true -- lets prioritize a, for no reason, lets make b angry.
end)
end
end
end
......
This diff is collapsed.
......@@ -50,7 +50,7 @@ function assert_table_equal(t1, t2, tables, checked)
end
end
function assert_exception(func, reason, msg)
function assert_exception(func, reason, msg, extra)
local ok, err = pcall(func)
lunit.assert_false(ok, "It hasn't failed")
local dumped, result = pcall(DataDumper, err)
......@@ -62,6 +62,13 @@ function assert_exception(func, reason, msg)
if msg then
lunit.assert_equal(msg, err.msg, "Failed with a wrong message " .. (err.msg or msg))
end
if extra then
local eerr = utils.shallow_copy(extra)
eerr.tp = 'error'
eerr.reason = err.reason
eerr.msg = err.msg
assert_table_equal(eerr, err)
end
end
mocks_called = {}
......
This diff is collapsed.
......@@ -187,8 +187,8 @@ function test_pkg_merge()
[""] = {
tp = 'pkg-list',
list = {
xyz = {Package = "xyz"},
abc = {Package = "abc"}
xyz = {Package = "xyz", Version = "1"},
abc = {Package = "abc", Version = "2"}
}
}
}
......@@ -198,19 +198,29 @@ function test_pkg_merge()
a = {
tp = 'pkg-list',
list = {
abc = {Package = "abc"}
abc = {Package = "abc", Version = "1"}
}
},
b = {
tp = 'pkg-list',
list = {
another = {Package = "another"}
another = {Package = "another", Version = "4"}
}
},
c = utils.exception("Just an exception", "Just an exception")
}
}
}
-- Add repo field
for _, repo in pairs(requests.known_repositories_all) do
for _, cont in pairs(repo.content) do
if cont.tp == 'pkg-list' then
for _, pkg in pairs(cont.list) do
pkg.repo = repo
end
end
end
end
requests.known_packages = {
{
tp = 'package',
......@@ -236,11 +246,14 @@ function test_pkg_merge()
-- Build the expected data structure
local exp = {
abc = {
candidates = {{Package = "abc", deps = {}}, {Package = "abc", deps = {}}},
candidates = {
{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", deps = {}}},
candidates = {{Package = "another", Version = "4", repo = requests.known_repositories_all[2]}},
modifier = {name = "another"}
},
virt = {
......@@ -249,7 +262,7 @@ function test_pkg_merge()
virtual = true
},
xyz = {
candidates = {{Package = "xyz", deps = {}}},
candidates = {{Package = "xyz", Version = "1", repo = requests.known_repositories_all[1]}},
modifier = {
name = "xyz",
order_after = {abc = true},
......
......@@ -112,6 +112,13 @@ function test_exception()
msg = "Error message"
}, e)
assert_equal("Error message", tostring(e))
local e = U.exception("reason", "msg", { extra = true })
assert_table_equal({
tp = "error",
reason = "reason",
msg = "msg",
extra = true
}, e)
end
function test_multi_index()
......
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