Commit d5b6e30e authored by Karel Koci's avatar Karel Koci 🤘

reimplement required_pkgs using sat solver and support request priority

Whole function required_pkgs is reimplemented. Its features are same as
previous implementation, except its now also solving cycles in
dependencies and implements priority precedence for requests.

Also all dependencies are now canonized, no matter where they came from.
parent c338c9b3
......@@ -155,23 +155,34 @@ end
--[[
Canonicize the dependencies somewhat. This does several things:
• Splits dependencies from strings (eg. "a b c" becomes a real dep-and object holding "a", "b", "c").
• Splits dependencies from strings (eg. "a, b, c" becomes a real dep-and object holding "a", "b", "c").
• Splits version limitations from dependency string (ex.: "a (>=1)" becomes { tp="dep-package", name="a", version=">=1" }).
• Table dependencies are turned to real dep-and object.
• Empty dependencies are turned to nil.
• Single dependencies are turned to just the string (except with the not dependency)
TODO: There may be versions. These are ignored for now.
]]
function deps_canon(old_deps)
if type(old_deps) == 'string' then
if old_deps:match('%s') then
if old_deps:match(',') then
local sub = {}
for dep in old_deps:gmatch('%S+') do
table.insert(sub, dep)
for dep in old_deps:gmatch('[^,]+') do
table.insert(sub, deps_canon(dep))
end
return deps_canon({
tp = 'dep-and',
sub = sub
})
elseif old_deps:match('%s') then
-- When there is space in parsed name, then there might be version specified
local dep = old_deps:gsub('^%s', ''):gsub('%s$', '')
local name = dep:match('^%S+')
local version = dep:match('%(.+%)$')
version = version and version:sub(2,-2):gsub('^%s', ''):gsub('%s$', '')
if not version or version == "" then
return name -- No version detected, use just name.
else
return { tp = "dep-package", name = name, version = version }
end
elseif old_deps == '' then
return nil
else
......@@ -325,6 +336,12 @@ function pkg_aggregate()
modifier.replan = modifier.replan or m.replan
end
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
end
pkg_group.modifier = modifier
-- We merged them together, they are no longer needed separately
pkg_group.modifiers = nil
......
This diff is collapsed.
......@@ -83,3 +83,7 @@ script::
dep-and, dep-or, dep-not::
Dependency composition objects. They contain the field `sub`, which
is a table of sub-dependencies.
dep-package::
Package description from dependencies. It must contain field `name`
containing name of package group and optionally also field
`version` containing version limitations.
......@@ -78,6 +78,7 @@ static int lua_picosat_assume(lua_State *L) {
if (lua_gettop(L) < 2)
return luaL_error(L, "picosat:assume requires one argument.");
int assum = luaL_checkinteger(L, 2);
ASSERT(assum != 0);
picosat_assume(ps->sat, assum);
return 0;
}
......
......@@ -21,7 +21,7 @@ globals = {
files["src/lib/autoload/a_04_utils.lua"] = {
globals = {
"lines2set", "map", "set2arr", "arr2set", "cleanup_dirs", "slurp", "clone", "shallow_copy", "table_merge", "arr_append", "exception", "multi_index", "private", "filter_best", "strip", "table_overlay", "randstr",
"lines2set", "map", "set2arr", "arr2set", "cleanup_dirs", "slurp", "clone", "shallow_copy", "table_merge", "arr_append", "exception", "multi_index", "private", "filter_best", "strip", "table_overlay", "randstr", "table_inv"
}
}
......@@ -74,7 +74,7 @@ files["src/lib/autoload/a_12_sat.lua"] = {
files["src/lib/autoload/a_13_planner.lua"] = {
globals = {
"candidate_choose", "required_pkgs", "filter_required",
"candidate_choose", "required_pkgs", "filter_required", "pkg_dep_iterate", "plan_sorter"
}
}
......
This diff is collapsed.
......@@ -236,20 +236,20 @@ function test_pkg_merge()
-- Build the expected data structure
local exp = {
abc = {
candidates = {{Package = "abc"}, {Package = "abc"}},
candidates = {{Package = "abc", deps = {}}, {Package = "abc", deps = {}}},
modifier = {name = "abc"}
},
another = {
candidates = {{Package = "another"}},
candidates = {{Package = "another", deps = {}}},
modifier = {name = "another"}
},
virt = {
candidates = {{tp = "package", name = "virt", deps = {"xyz", "abc"}, virtual = true}},
candidates = {{tp = "package", name = "virt", deps = {tp = "dep-and", sub = {"xyz", "abc"}}, virtual = true}},
modifier = {name = "virt"},
virtual = true
},
xyz = {
candidates = {{Package = "xyz"}},
candidates = {{Package = "xyz", deps = {}}},
modifier = {
name = "xyz",
order_after = {abc = true},
......@@ -294,9 +294,12 @@ function test_deps_canon()
assert_equal("x", postprocess.deps_canon({"x"}))
assert_equal("x", postprocess.deps_canon({tp = 'dep-and', sub = {"x"}}))
assert_equal("x", postprocess.deps_canon({tp = 'dep-or', sub = {"x"}}))
assert_equal("x", postprocess.deps_canon("x ( )"))
assert_table_equal({tp = "dep-package", name = "x", version = ">1.25"}, postprocess.deps_canon("x (>1.25)"))
assert_table_equal({tp = "dep-package", name = "x", version = ">v_12"}, postprocess.deps_canon("x ( >v_12)"))
assert_table_equal({tp = "dep-not", sub = {"x"}}, postprocess.deps_canon({tp = 'dep-not', sub = {"x"}}))
assert_table_equal({tp = "dep-and", sub = {"x", "y"}}, postprocess.deps_canon("x y"))
assert_table_equal({tp = "dep-and", sub = {"x", "y"}}, postprocess.deps_canon({"x y"}))
assert_table_equal({tp = "dep-and", sub = {"x", "y"}}, postprocess.deps_canon("x, y"))
assert_table_equal({tp = "dep-and", sub = {"x", "y"}}, postprocess.deps_canon({"x, y"}))
assert_table_equal({tp = "dep-and", sub = {"x", "y"}}, postprocess.deps_canon({"x", "y"}))
assert_table_equal({tp = "dep-and", sub = {"x", "y"}}, postprocess.deps_canon({"x", {"y "}}))
assert_table_equal({tp = "dep-and", sub = {"x", "y"}}, postprocess.deps_canon({"x", {tp = 'dep-and', sub = {"y "}}}))
......
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