ap/aports.lua: implement recurse_until

will recursively parse all build depends
This commit is contained in:
Natanael Copa 2011-03-30 13:10:06 +02:00
parent dee681905f
commit 486959e2db
2 changed files with 47 additions and 21 deletions

26
ap.in
View File

@ -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

View File

@ -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