2013-08-01 06:41:09 +00:00
|
|
|
#!@LUA_SHEBANG@
|
2010-12-13 14:14:06 +00:00
|
|
|
|
2013-04-23 07:41:27 +00:00
|
|
|
aports = require("aports")
|
|
|
|
lfs = require("lfs")
|
2010-12-13 14:14:06 +00:00
|
|
|
|
2011-06-15 08:24:31 +00:00
|
|
|
local db
|
|
|
|
|
2011-09-30 12:44:43 +00:00
|
|
|
local function build_is_outdated(pkg)
|
|
|
|
local apk_attr = lfs.attributes(aports.get_apk_file_path(pkg))
|
|
|
|
local apkbuild_attr = lfs.attributes(pkg.dir.."/APKBUILD")
|
|
|
|
if apk_attr == nil then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return os.difftime(apk_attr.modification, apkbuild_attr.modification) < 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local function build_is_missing(pkg)
|
|
|
|
return lfs.attributes(aports.get_apk_file_path(pkg)) == nil
|
|
|
|
end
|
|
|
|
|
2010-12-13 14:14:06 +00:00
|
|
|
-- subcommands -----------------------
|
|
|
|
subcmd = {}
|
|
|
|
subcmd.revdep = {
|
|
|
|
desc = "Print reverse dependencies",
|
|
|
|
usage = "PKG...",
|
|
|
|
run = function(opts)
|
|
|
|
local i
|
2011-09-30 09:25:52 +00:00
|
|
|
for i = 1, #opts do
|
2011-06-15 08:24:31 +00:00
|
|
|
db:foreach_revdep(opts[i], function (k,p)
|
|
|
|
print(p.pkgname)
|
|
|
|
end)
|
2010-12-13 14:14:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
subcmd.list = {
|
|
|
|
desc = "Print all packages built from aports tree",
|
|
|
|
usage = "",
|
|
|
|
run = function()
|
2011-06-15 08:24:31 +00:00
|
|
|
db:foreach(function (k)
|
2010-12-13 14:14:06 +00:00
|
|
|
print(k)
|
2011-06-15 08:24:31 +00:00
|
|
|
end)
|
2010-12-13 14:14:06 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
subcmd.recursdeps = {
|
|
|
|
desc = "Recursively print all make dependencies for given packages",
|
|
|
|
usage = "PKG...",
|
|
|
|
run = function (opts)
|
2011-09-30 09:25:52 +00:00
|
|
|
for i = 1, #opts do
|
2011-06-15 08:24:31 +00:00
|
|
|
db:recurs_until(opts[i], function(pn)
|
2011-03-30 11:10:06 +00:00
|
|
|
print(pn)
|
|
|
|
end)
|
2010-12-13 14:14:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
subcmd.builddirs = {
|
|
|
|
desc = "Print the build dirs for given packages in build order",
|
|
|
|
usage = "PKG...",
|
|
|
|
run = function(opts)
|
2010-12-13 14:51:29 +00:00
|
|
|
local i, p, _
|
2010-12-13 14:14:06 +00:00
|
|
|
local visited = {}
|
|
|
|
local to_print = {}
|
2011-09-30 09:25:52 +00:00
|
|
|
for i = 1, #opts do
|
2011-06-15 08:24:31 +00:00
|
|
|
db:foreach_pkg(opts[i], function(_, p)
|
2010-12-13 14:51:29 +00:00
|
|
|
to_print[p.dir] = true
|
2011-06-15 08:24:31 +00:00
|
|
|
end)
|
2010-12-13 14:14:06 +00:00
|
|
|
end
|
2011-09-30 09:25:52 +00:00
|
|
|
for i = 1, #opts do
|
2011-06-15 08:24:31 +00:00
|
|
|
db:recurs_until(opts[i], function(pn)
|
2011-03-30 11:40:47 +00:00
|
|
|
local j,p
|
2011-06-15 08:24:31 +00:00
|
|
|
db:foreach_pkg(pn, function(j, p)
|
2011-03-30 11:40:47 +00:00
|
|
|
if to_print[p.dir] then
|
|
|
|
print(p.dir)
|
|
|
|
to_print[p.dir] = nil
|
|
|
|
end
|
2011-06-15 08:24:31 +00:00
|
|
|
end)
|
2011-03-30 11:40:47 +00:00
|
|
|
end)
|
2010-12-13 14:14:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2011-08-04 12:21:32 +00:00
|
|
|
subcmd.sources = {
|
|
|
|
desc = "List sources",
|
|
|
|
usage = "PKG...",
|
|
|
|
run = function(opts)
|
|
|
|
local i, p, _
|
2011-09-30 09:25:52 +00:00
|
|
|
for i = 1, #opts do
|
2011-08-04 12:21:32 +00:00
|
|
|
db:foreach_pkg(opts[i], function(_, p)
|
|
|
|
aports.foreach_remote_source(p, function(url)
|
|
|
|
print(p.pkgname, p.pkgver, string.gsub(url, p.pkgver, "$VERSION"))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
2010-12-13 14:14:06 +00:00
|
|
|
|
2011-09-30 12:44:43 +00:00
|
|
|
subcmd["rebuild-list"] = {
|
|
|
|
desc = "List packages that can/should be rebuilt",
|
|
|
|
usage = "",
|
|
|
|
run = function()
|
|
|
|
local outdated = {}
|
|
|
|
db:foreach(function(k)
|
|
|
|
db:foreach_pkg(k, function(_, p)
|
|
|
|
if build_is_outdated(p) then
|
|
|
|
table.insert(outdated, p.pkgname)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
-- print build dirs in build sort order
|
|
|
|
subcmd.builddirs.run(outdated)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
subcmd["build-list"] = {
|
|
|
|
desc = "List packages that is not built",
|
|
|
|
usage = "",
|
|
|
|
run = function()
|
|
|
|
local missing = {}
|
|
|
|
db:foreach(function(k)
|
|
|
|
db:foreach_pkg(k, function(_, p)
|
|
|
|
if build_is_missing(p) then
|
|
|
|
table.insert(missing, p.pkgname)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
-- print build dirs in build sort order
|
|
|
|
subcmd.builddirs.run(missing)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2013-04-23 07:41:27 +00:00
|
|
|
subcmd["list-apks"] = {
|
|
|
|
desc = "List all apk files",
|
|
|
|
usage = "",
|
|
|
|
run = function()
|
|
|
|
db:foreach(function(k)
|
|
|
|
db:foreach_pkg(k, function(_, p)
|
|
|
|
print(aports.get_apk_filename(p))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2010-12-13 14:14:06 +00:00
|
|
|
function print_usage()
|
2010-12-13 15:03:11 +00:00
|
|
|
io.write("usage: ap -d <DIR> SUBCOMMAND [options]\n\nSubcommands are:\n")
|
2010-12-13 14:14:06 +00:00
|
|
|
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
|
|
|
|
|
2011-03-30 11:10:06 +00:00
|
|
|
|
2011-09-30 09:25:52 +00:00
|
|
|
cmd = table.remove(opts, 1)
|
2010-12-13 14:14:06 +00:00
|
|
|
|
|
|
|
if cmd == nil then
|
|
|
|
print_usage()
|
|
|
|
-- usage
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2011-07-06 06:30:42 +00:00
|
|
|
if #repodirs == 0 then
|
|
|
|
if lfs.attributes("APKBUILD") then
|
|
|
|
repodirs[1] = string.gsub(lfs.currentdir(), "(.*)/.*", "%1")
|
|
|
|
else
|
|
|
|
repodirs[1] = lfs.currentdir()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-13 14:14:06 +00:00
|
|
|
if subcmd[cmd] and type(subcmd[cmd].run) == "function" then
|
2011-06-15 08:24:31 +00:00
|
|
|
db = aports.new(repodirs)
|
2011-09-30 12:44:43 +00:00
|
|
|
loadtime = os.clock()
|
2010-12-13 14:14:06 +00:00
|
|
|
subcmd[cmd].run(opts)
|
2011-09-30 12:44:43 +00:00
|
|
|
runtime = os.clock() - loadtime
|
|
|
|
-- io.stderr:write("db load time = "..tostring(loadtime).."\n")
|
|
|
|
-- io.stderr:write("cmd run time = "..tostring(runtime).."\n")
|
2010-12-13 14:14:06 +00:00
|
|
|
else
|
|
|
|
io.stderr:write(cmd..": invalid subcommand\n")
|
|
|
|
end
|
|
|
|
|