diff --git a/ap.in b/ap.in index 3d5925b..b0b973e 100755 --- a/ap.in +++ b/ap.in @@ -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 diff --git a/aports.lua b/aports.lua index 44691c8..f8a0121 100755 --- a/aports.lua +++ b/aports.lua @@ -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 +