Commit 486959e2 authored by Natanael Copa's avatar Natanael Copa

ap/aports.lua: implement recurse_until

will recursively parse all build depends
parent dee68190
......@@ -36,28 +36,11 @@ subcmd.recursdeps = {
desc = "Recursively print all make dependencies for given packages",
usage = "PKG...",
run = function (opts)
local i
local visited = {}
local apkdb, rev = aports.init_apkdb(repodirs)
function recurs(pn)
if pn == nil or visited[pn] or apkdb[pn] == nil then
return
end
visited[pn] = true
local i,d, p
for i,p in pairs(apkdb[pn]) do
local _, d
for _, d in pairs(p.depends) do
recurs(d)
end
for _, d in pairs(p.makedepends) do
recurs(d)
end
end
print(pn)
end
local db, rev = aports.init_apkdb(repodirs)
for i = 2, #opts do
recurs(opts[i])
aports.recurs_until(db, opts[i], function(pn)
print(pn)
end)
end
end
}
......@@ -130,6 +113,7 @@ while i <= #arg do
i = i + 1
end
cmd = opts[1]
if cmd == nil then
......
......@@ -103,3 +103,45 @@ function init_apkdb(repodirs)
return pkgdb, revdeps
end
-- return a key list with makedepends and depends
function all_deps(p)
local m = {}
local k,v
if p == nil then
return m
end
if type(p.depends) == "table" then
for k,v in pairs(p.depends) do
m[v] = true
end
end
if type(p.makedepends) == "table" then
for k,v in pairs(p.makedepends) do
m[v] = true
end
end
return m
end
function recurs_until(apkdb, pn, func)
local visited={}
function recurs(pn)
if pn == nil or visited[pn] or apkdb[pn] == nil then
return false
end
visited[pn] = true
local _, p
for _, p in pairs(apkdb[pn]) do
local d
for d in pairs(all_deps(p)) do
if recurs(d) then
return true
end
end
end
return func(pn)
end
return recurs(pn)
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