Commit 09b83ea1 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

migrator: Omit the non-head packages

Omit the packages that something else depends on. They would be pulled
in as dependencies of the other packages, so they don't have to be
listed explicitly.
parent 3986cf11
......@@ -20,10 +20,13 @@ along with Updater. If not, see <http://www.gnu.org/licenses/>.
-- luacheck: globals extra_pkgs pkgs_format
local pairs = pairs
local ipairs = ipairs
local type = type
local table = table
local utils = require "utils"
local backend = require "backend"
local updater = require "updater"
local postprocess = require "postprocess"
module "migrator"
......@@ -44,6 +47,35 @@ function extra_pkgs(entry_point)
end
end
end
--[[
Eliminate packages that are depended on by other packages that we
want to list. That way we would only list the „heads“, and wouldn't
pull in all the list of deep dependencies.
]]
local function eliminate(dep)
local tp = type(dep)
if tp == 'string' then
result[dep] = nil
elseif tp == 'table' then
if dep.tp == 'package' or dep.tp == 'dep-package' then
result[dep.name] = nil
elseif dep.tp == 'dep-and' then
-- The real dependencies are in sub
return eliminate(dep.sub)
elseif dep.tp == nil then
-- Just a plain table
for _, d in ipairs(dep) do
eliminate(d)
end
end -- Ignore all the dep-or and dep-not stuff as too complex
end
end
for name in pairs(utils.shallow_copy(result)) do -- Iterate over a copy, so we don't delete one dep and then miss its deps because it was no longer ehere
-- As we don't want to care about choosing the candidate, use what is installed. But clean up the dependencies first.
eliminate(postprocess.deps_canon(utils.multi_index(installed, name, "Depends") or {}))
-- The modifier is common for all. Use that one.
eliminate(utils.multi_index(postprocess.available_packages, name, "modifier", "deps"))
end
return result
end
......
......@@ -36,7 +36,7 @@ YYY
]], migrator.pkgs_format(pkgs, "", ""))
end
function test_extra_pkgs()
local function mocks(status_mod)
mock_gen("updater.required_pkgs", function () return {
{
action = 'reinstall',
......@@ -61,8 +61,15 @@ function test_extra_pkgs()
end)
-- This one is mentioned but not actually installed, so check it doesn't get confused by that
status.pkg4.Status[3] = 'not-installed'
if status_mod then
status_mod(status)
end
return status
end)
end
function test_extra_pkgs()
mocks()
local result = migrator.extra_pkgs('epoint')
--[[
pkg1 not present, since it is required by the current configs
......@@ -84,6 +91,31 @@ function test_extra_pkgs()
}, mocks_called)
end
-- Just like test_extra_pkgs, but pkg3 depends on pkg5. Therefore we don't list pkg5.
function test_extra_pkgs_dep_status()
mocks(function (status) status.pkg5.Depends = {"pkg3 (>= 14.4)"} end)
local result = migrator.extra_pkgs('epoint')
assert_table_equal({pkg5 = true}, result)
end
-- The same as test_extra_pkgs_dep_status, but the dep is added as a modifier
function test_extra_pkgs_dep_modifier()
mocks()
postprocess.available_packages.pkg5 = {
tp = "package",
name = "pkg5",
modifier = {
deps = {
tp = 'dep-and',
sub = {'pkg3'}
}
}
}
local result = migrator.extra_pkgs('epoint')
assert_table_equal({pkg5 = true}, result)
end
function teardown()
postprocess.available_packages = {}
mocks_reset()
end
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