summaryrefslogtreecommitdiffstats
path: root/ap.in
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2010-12-13 14:14:06 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2010-12-13 14:14:06 +0000
commitce0e95607d04e95b0d07a11aacbaaa4dae26bfd7 (patch)
treeb4be1b4af61426a7a7090dda0afe850bad42a4a8 /ap.in
parenta111620bc8b8bbd72295c899acf5a7dca87e210c (diff)
downloadabuild-ce0e95607d04e95b0d07a11aacbaaa4dae26bfd7.tar.bz2
abuild-ce0e95607d04e95b0d07a11aacbaaa4dae26bfd7.tar.xz
ap: initial implementation
ap is a helper script to parse APKBUILD and calculate build time dependencies.
Diffstat (limited to 'ap.in')
-rwxr-xr-xap.in147
1 files changed, 147 insertions, 0 deletions
diff --git a/ap.in b/ap.in
new file mode 100755
index 0000000..64b7cf9
--- /dev/null
+++ b/ap.in
@@ -0,0 +1,147 @@
+#!/usr/bin/lua
+
+require("aports")
+
+-- subcommands -----------------------
+subcmd = {}
+subcmd.revdep = {
+ desc = "Print reverse dependencies",
+ usage = "PKG...",
+ run = function(opts)
+ local i
+ local apkdb, rev = aports.init_apkdb(repodirs)
+ for i = 2, #opts do
+ local pkg = opts[i]
+ local _,p
+ for _,p in ipairs(rev[pkg] or {}) do
+ print(p.pkgname)
+ end
+ end
+ end
+}
+
+subcmd.list = {
+ desc = "Print all packages built from aports tree",
+ usage = "",
+ run = function()
+ local apkdb = aports.init_apkdb(repodirs)
+ local k,v
+ for k,v in pairs(apkdb) do
+ print(k)
+ end
+ end
+}
+
+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 ipairs(apkdb[pn]) do
+ local _, d
+ for _, d in ipairs(p.depends) do
+ recurs(d)
+ end
+ for _, d in ipairs(p.makedepends) do
+ recurs(d)
+ end
+ end
+ print(pn)
+ end
+ for i = 2, #opts do
+ recurs(opts[i])
+ end
+ end
+}
+
+subcmd.builddirs = {
+ desc = "Print the build dirs for given packages in build order",
+ usage = "PKG...",
+ run = function(opts)
+ local i, _
+ local visited = {}
+ local dir_visited = {}
+ local apkdb, rev = aports.init_apkdb(repodirs)
+ local to_print = {}
+ function recursdir(pn)
+ if pn == nil or visited[pn] or apkdb[pn] == nil then
+ return
+ end
+ visited[pn] = true
+ local i, p
+ for i,p in pairs(apkdb[pn]) do
+ if not dir_visited[p.dir] then
+ dir_visited[p.dir] = true
+ local _, d
+ for _, d in pairs(p.depends) do
+ recursdir(d)
+ end
+ for _, d in pairs(p.makedepends) do
+ recursdir(d)
+ end
+ if to_print[pn] then
+ print(p.dir)
+ end
+ end
+ end
+ end
+ for i = 2, #opts do
+ to_print[opts[i]] = true
+ end
+ for i = 2, #opts do
+ recursdir(opts[i])
+ end
+ end
+}
+
+
+function print_usage()
+ io.write("usage: ap SUBCOMMAND [options]\n\nSubcommands are:\n")
+ local k,v
+ for k in pairs(subcmd) do
+ print(" "..k)
+ end
+end
+
+-- those should be read from some config file
+repodirs = {}
+
+
+-- parse args
+i = 1
+opts = {}
+help = false
+while i <= #arg do
+ if arg[i] == "-d" then
+ i = i + 1
+ repodirs[#repodirs + 1] = arg[i]
+ elseif arg[i] == "-h" then
+ help = true
+ else
+ opts[#opts + 1] = arg[i]
+ end
+ i = i + 1
+end
+
+cmd = opts[1]
+
+if cmd == nil then
+ print_usage()
+ -- usage
+ return
+end
+
+if subcmd[cmd] and type(subcmd[cmd].run) == "function" then
+ subcmd[cmd].run(opts)
+else
+ io.stderr:write(cmd..": invalid subcommand\n")
+end
+