summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xap.lua51
-rw-r--r--aports/apkrepo.lua13
-rw-r--r--aports/db.lua70
-rw-r--r--aports/pkg.lua28
-rwxr-xr-xbuildrepo.lua30
5 files changed, 80 insertions, 112 deletions
diff --git a/ap.lua b/ap.lua
index c77670a..1251064 100755
--- a/ap.lua
+++ b/ap.lua
@@ -2,18 +2,6 @@
local lfs = require('lfs')
-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
-- subcommands -----------------------
local subcmd = {}
@@ -22,9 +10,8 @@ subcmd.revdep = {
desc = "Print reverse dependencies",
usage = "PKG...",
run = function(db, opts)
- local i
for i = 1, #opts do
- for _,pkg in db:each_reverse_dependency(opts[i]) do
+ for _, pkg in db:each_reverse_dependency(opts[i]) do
print(pkg.pkgname)
end
end
@@ -67,7 +54,6 @@ subcmd.sources = {
desc = "List sources",
usage = "PKG...",
run = function(db, opts)
- local i, p, _
for i = 1, #opts do
for pkg in db:each_pkg_with_name(opts[i]) do
for url in pkg:remote_sources() do
@@ -114,7 +100,6 @@ subcmd["dump-json"] = {
local function print_usage()
io.write("usage: ap -d <DIR> SUBCOMMAND [options]\n\nSubcommands are:\n")
- local k,v
for k in pairs(subcmd) do
print(" "..k)
end
@@ -125,25 +110,26 @@ local repodirs = {}
-- parse args
-local i = 1
local opts = {}
local help = false
-while i <= #arg do
- if arg[i] == "-d" then
+do
+ local i = 1
+ 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
- repodirs[#repodirs + 1] = arg[i]
- elseif arg[i] == "-h" then
- help = true
- else
- opts[#opts + 1] = arg[i]
end
- i = i + 1
end
-
local cmd = table.remove(opts, 1)
-if help or cmd == nil then
+if help or not cmd then
print_usage()
-- usage
return
@@ -158,15 +144,10 @@ if #repodirs == 0 then
end
if subcmd[cmd] and type(subcmd[cmd].run) == "function" then
- for _,dir in pairs(repodirs) do
- local db = require('aports.db').new(dir:match("(.*)/([^/]*)"))
- local loadtime = os.clock()
- subcmd[cmd].run(db, opts)
- local runtime = os.clock() - loadtime
--- io.stderr:write("db load time = "..tostring(loadtime).."\n")
--- io.stderr:write("cmd run time = "..tostring(runtime).."\n")
+ for _, dir in pairs(repodirs) do
+ local db = require('aports.db').new(dir:match("(.*)/([^/]*)"))
+ subcmd[cmd].run(db, opts)
end
else
io.stderr:write(cmd..": invalid subcommand\n")
end
-
diff --git a/aports/apkrepo.lua b/aports/apkrepo.lua
index 4418670..16a41c4 100644
--- a/aports/apkrepo.lua
+++ b/aports/apkrepo.lua
@@ -1,22 +1,23 @@
-local M = {}
-
local lfs = require('lfs')
+local M = {}
+
function M.update_index(dir, arch, description)
- local indexopt=""
- local descriptionopt=""
+ local indexopt = ""
+ local descriptionopt = ""
local olddir = lfs.currentdir()
local archdir = ("%s/%s"):format(dir, arch)
assert(lfs.chdir(archdir), archdir)
local signed_index = "APKINDEX.tar.gz"
local unsigned_index = "APKINDEX.tar.gz.unsigned"
- if lfs.attributes(signed_index) ~= nil then
+ if lfs.attributes(signed_index) then
indexopt = "--index "..signed_index
end
if description then
descriptionopt="--description "..description
end
- local indexcmd = ("apk index --quiet %s %s --output '%s' --rewrite-arch %s *.apk"):format(indexopt, descriptionopt, unsigned_index, arch)
+ local indexcmd = ("apk index --quiet %s %s --output '%s' --rewrite-arch %s *.apk")
+ :format(indexopt, descriptionopt, unsigned_index, arch)
local signcmd = "abuild-sign -q "..unsigned_index
assert(os.execute(indexcmd), indexcmd)
assert(os.execute(signcmd), signcmd)
diff --git a/aports/db.lua b/aports/db.lua
index ca47491..a087020 100644
--- a/aports/db.lua
+++ b/aports/db.lua
@@ -5,14 +5,13 @@ local pkg = require('aports.pkg')
local function split_subpkgs(str, linguas, pkgname)
local t = {}
- local e
- if (str == nil) then
+ if not str then
return nil
end
for e in string.gmatch(str, "%S+") do
t[#t + 1] = string.gsub(e, ":.*", "")
end
- for k,v in pairs(linguas) do
+ for _, v in pairs(linguas) do
t[#t + 1] = ("%s-lang-%s"):format(pkgname, v)
end
return t
@@ -20,8 +19,7 @@ end
local function split_deps(str)
local t = {}
- local e
- if (str == nil) then
+ if not str then
return nil
end
for e in string.gmatch(str, "%S+") do
@@ -32,8 +30,7 @@ end
local function split(str)
local t = {}
- local e
- if (str == nil) then
+ if not str then
return nil
end
for e in string.gmatch(str, "%S+") do
@@ -44,14 +41,14 @@ end
local function split_key(str)
local t = {}
- for _,key in pairs(split(str)) do
+ for _, key in pairs(split(str)) do
t[key] = true
end
return t
end
local function split_apkbuild(line)
- if line == nil then
+ if not line then
return nil
end
local dir, pkgname, pkgver, pkgrel, pkgdesc, arch, license, options, depends,
@@ -80,13 +77,12 @@ end
-- parse the APKBUILDs and return an iterator
local function apkbuilds_open(aportsdir, repos)
- local i,v, p
- local str=""
- if repos == nil then
+ local str = ""
+ if not repos then
return nil
end
--expand repos
- for _,repo in pairs(repos) do
+ for _, repo in pairs(repos) do
str = ("%s %s/%s/*/APKBUILD"):format(str, aportsdir, repo)
end
@@ -118,7 +114,6 @@ local function apkbuilds_open(aportsdir, repos)
return function()
return split_apkbuild(self.handle:read("*line"))
end
-
end
obj.close = function(self)
return self.handle:close()
@@ -138,8 +133,7 @@ local function init_apkdb(aportsdir, repos, repodest)
pkg.init(a, repodest)
table.insert(pkgdb[a.pkgname], a)
-- add subpackages to package db
- local k,v
- for k,v in pairs(a.subpackages) do
+ for _, v in pairs(a.subpackages) do
if pkgdb[v] == nil then
pkgdb[v] = {}
end
@@ -160,17 +154,16 @@ local function init_apkdb(aportsdir, repos, repodest)
end
local Aports = {}
-function Aports:recursive_dependencies(pn)
+function Aports:recursive_dependencies(pkgname)
local visited={}
local apkdb = self.apks
return coroutine.wrap(function()
- function recurs(pn)
- if pn == nil or visited[pn] or apkdb[pn] == nil then
+ local function recurs(pn)
+ if not pn or visited[pn] or not apkdb[pn] then
return nil
end
visited[pn] = true
- local _, p
for _, p in pairs(apkdb[pn]) do
for dep in p:each_dependency() do
if recurs(dep) then
@@ -180,36 +173,35 @@ function Aports:recursive_dependencies(pn)
end
coroutine.yield(pn)
end
- return recurs(pn)
+ return recurs(pkgname)
end)
end
function Aports:target_packages(pkgname)
return coroutine.wrap(function()
- for k,v in pairs(self.apks[pkgname]) do
+ for _, v in pairs(self.apks[pkgname]) do
coroutine.yield(pkgname.."-"..v.pkgver.."-r"..v.pkgrel..".apk")
end
end)
end
function Aports:each_name()
- local apks = self.apks
return coroutine.wrap(function()
- for k,v in pairs(self.apks) do
- coroutine.yield(k,v)
+ for k, v in pairs(self.apks) do
+ coroutine.yield(k, v)
end
end)
end
-function Aports:each_reverse_dependency(pkg)
+function Aports:each_reverse_dependency(pkg) --luacheck: ignore 431
return coroutine.wrap(function()
- for k,v in pairs(self.revdeps[pkg] or {}) do
- coroutine.yield(k,v)
+ for k, v in pairs(self.revdeps[pkg] or {}) do
+ coroutine.yield(k, v)
end
end)
end
-function Aports:each_known_dependency(pkg)
+function Aports:each_known_dependency(pkg) --luacheck: ignore 431
return coroutine.wrap(function()
for dep in pkg:each_dependency() do
if self.apks[dep] then
@@ -220,12 +212,12 @@ function Aports:each_known_dependency(pkg)
end
function Aports:each_pkg_with_name(name)
- if self.apks[name] == nil then
+ if not self.apks[name] then
io.stderr:write("WARNING: "..name..": not provided by any known APKBUILD\n")
return function() return nil end
end
return coroutine.wrap(function()
- for index, pkg in pairs(self.apks[name]) do
+ for index, pkg in pairs(self.apks[name]) do --luacheck: ignore 431
coroutine.yield(pkg, index)
end
end)
@@ -234,7 +226,7 @@ end
function Aports:each()
return coroutine.wrap(function()
for name, pkglist in self:each_name() do
- for _, pkg in pairs(pkglist) do
+ for _, pkg in pairs(pkglist) do --luacheck: ignore 431
coroutine.yield(pkg, name)
end
end
@@ -243,7 +235,7 @@ end
function Aports:each_aport()
return coroutine.wrap(function()
- for pkg, name in self:each() do
+ for pkg, name in self:each() do --luacheck: ignore 431
if name == pkg.pkgname then
coroutine.yield(pkg)
end
@@ -263,16 +255,16 @@ end
function Aports:each_in_build_order(namelist)
local pkgs = {}
- for _,name in pairs(namelist) do
- for pkg in self:each_pkg_with_name(name) do
+ for _, name in pairs(namelist) do
+ for pkg in self:each_pkg_with_name(name) do --luacheck: ignore 431
pkgs[pkg.dir] = true
end
end
return coroutine.wrap(function()
- for _,name in pairs(namelist) do
+ for _, name in pairs(namelist) do
for dep in self:recursive_dependencies(name) do
- for pkg in self:each_pkg_with_name(dep) do
+ for pkg in self:each_pkg_with_name(dep) do --luacheck: ignore 431
if pkgs[pkg.dir] then
coroutine.yield(pkg)
pkgs[pkg.dir] = nil
@@ -286,7 +278,7 @@ end
function Aports:git_describe()
local cmd = ("git --git-dir %s/.git describe"):format(self.aportsdir)
local f = io.popen(cmd)
- if f == nil then
+ if not f then
return nil
end
local result = f:read("*line")
@@ -295,7 +287,7 @@ function Aports:git_describe()
return result
end
-function Aports:known_deps_exists(pkg)
+function Aports:known_deps_exists(pkg) --luacheck: ignore 431
for name in self:each_known_dependency(pkg) do
for dep in self:each_pkg_with_name(name) do
if dep.pkgname ~= pkg.pkgname and dep:relevant() and not dep:all_apks_exists() then
diff --git a/aports/pkg.lua b/aports/pkg.lua
index 5d40db5..ddb30c0 100644
--- a/aports/pkg.lua
+++ b/aports/pkg.lua
@@ -4,8 +4,7 @@ local abuild = require('aports.abuild')
local lfs = require('lfs')
function M.is_remote(url)
- local _,pref
- for _,pref in pairs{ "^http://", "^ftp://", "^https://", ".*::.*" } do
+ for _, pref in pairs{ "^http://", "^ftp://", "^https://", ".*::.*" } do
if string.match(url, pref) then
return true
end
@@ -15,11 +14,11 @@ end
-- iterator for all remote sources of given pkg/aport
function M.remote_sources(p)
- if p == nil or type(p.source) ~= "table" then
+ if not p or type(p.source) ~= "table" then
return nil
end
return coroutine.wrap(function()
- for _,url in pairs(p.source) do
+ for _, url in pairs(p.source) do
if M.is_remote(url) then
coroutine.yield(url)
end
@@ -28,14 +27,13 @@ function M.remote_sources(p)
end
function M.get_maintainer(pkg)
- if pkg == nil or pkg.dir == nil then
+ if not pkg or not pkg.dir then
return nil
end
local f = io.open(pkg.dir.."/APKBUILD")
- if f == nil then
+ if not f then
return nil
end
- local line
for line in f:lines() do
local maintainer = line:match("^%s*#%s*Maintainer:%s*(.*)")
if maintainer then
@@ -48,7 +46,7 @@ function M.get_maintainer(pkg)
end
function M.get_repo_name(pkg)
- if pkg == nil or pkg.dir == nil then
+ if not pkg or not pkg.dir then
return nil
end
return string.match(pkg.dir, ".*/(.*)/.*")
@@ -72,7 +70,7 @@ end
function M.apk_file_exists(pkg, name)
-- technically we check if it is readable...
local filepath = M.get_apk_file_path(pkg, name)
- if lfs.attributes(filepath) == nil then
+ if not lfs.attributes(filepath) then
io.stderr:write(("DEBUG: path=%s\n"):format(filepath))
end
return lfs.attributes(filepath) ~= nil
@@ -91,7 +89,8 @@ function M.all_apks_exists(pkg)
end
function M.arch_enabled(pkg)
- return not pkg.arch["!"..abuild.arch] and (pkg.arch.all or pkg.arch.noarch or pkg.arch[abuild.arch])
+ return not pkg.arch["!"..abuild.arch]
+ and (pkg.arch.all or pkg.arch.noarch or pkg.arch[abuild.arch])
end
function M.libc_enabled(pkg)
@@ -104,21 +103,20 @@ end
function M.each_dependency(pkg)
return coroutine.wrap(function()
- for _,dep in pairs(pkg.depends or {}) do
+ for _, dep in pairs(pkg.depends or {}) do
coroutine.yield(dep)
end
- for _,dep in pairs(pkg.makedepends or {}) do
+ for _, dep in pairs(pkg.makedepends or {}) do
coroutine.yield(dep)
end
- for _,dep in pairs(pkg.checkdepends or {}) do
+ for _, dep in pairs(pkg.checkdepends or {}) do
coroutine.yield(dep)
end
end)
end
-
function M.init(pkg, repodest)
- for k,v in pairs(M) do
+ for k, v in pairs(M) do
pkg[k] = v
end
pkg.repodest = repodest
diff --git a/buildrepo.lua b/buildrepo.lua
index 10123b3..7f6b886 100755
--- a/buildrepo.lua
+++ b/buildrepo.lua
@@ -17,11 +17,6 @@ local function err(formatstr, ...)
io.stderr:flush()
end
-local function fatal(exitcode, formatstr, ...)
- err(formatstr, ...)
- os.exit(exitcode)
-end
-
local function info(formatstr, ...)
io.stdout:write(("%s\n"):format(formatstr:format(...)))
io.stdout:flush()
@@ -42,7 +37,7 @@ end
local function run_plugins(dirpath, func, ...)
local a = lfs.attributes(dirpath)
- if a == nil or a.mode ~= "directory" then
+ if not a or a.mode ~= "directory" then
return
end
local flist = {}
@@ -52,7 +47,7 @@ local function run_plugins(dirpath, func, ...)
end
end
table.sort(flist)
- for i = 1,#flist do
+ for i = 1, #flist do
local m = dofile(dirpath.."/"..flist[i])
if type(m[func]) == "function" then
m[func](...)
@@ -77,7 +72,7 @@ local function plugins_postrepo(...)
end
local function logfile_path(logdirbase, repo, aport)
- if logdirbase == nil then
+ if not logdirbase then
return nil
end
local dir = ("%s/%s/%s"):format(logdirbase, repo, aport.pkgname)
@@ -132,13 +127,13 @@ local opthelp = [[
local function usage(exitcode)
io.stdout:write((
-"Usage: %s [-hknps] [-a DIR] [-d DIR] [-l DIR] [-r REPO] REPO...\n"..
-"Options:\n%s\n"):format(_G.arg[0], opthelp))
+ "Usage: %s [-hknps] [-a DIR] [-d DIR] [-l DIR] [-r REPO] REPO...\n"..
+ "Options:\n%s\n"):format(_G.arg[0], opthelp))
os.exit(exitcode)
end
local opts, args = optarg.from_opthelp(opthelp)
-if opts == nil or #args == 0 then
+if not opts or #args == 0 then
usage(1)
end
@@ -156,15 +151,14 @@ if opts.n then
end
local stats = {}
-for _,repo in pairs(args) do
+for _, repo in pairs(args) do
local db = require('aports.db').new(aportsdir, repo, repodest)
local pkgs = {}
local unsorted = {}
- local logdir = nil
stats[repo] = {}
local start_time = os.clock()
- if db == nil then
+ if not db then
err("%s/%s: Failed to open apkbuilds", aportsdir, repo)
os.exit(1)
end
@@ -199,7 +193,9 @@ for _,repo in pairs(args) do
for aport in db:each_in_build_order(pkgs) do
local logfile = logfile_path(logdirbase, repo, aport)
tried = tried + 1
- local progress = { tried = tried, total = #pkgs,
+ local progress = {
+ tried = tried,
+ total = #pkgs,
repo_built = stats[repo].relevant_aports - #pkgs + built,
repo_total = stats[repo].relevant_aports,
}
@@ -223,7 +219,7 @@ for _,repo in pairs(args) do
local deleted = 0
if opts.p then
local keep = {}
- for aport,name in db:each() do
+ for aport, name in db:each() do
keep[aport:get_apk_file_name(name)] = true
end
local apkrepodir = ("%s/%s/%s"):format(repodest, repo, abuild.arch)
@@ -253,7 +249,7 @@ for _,repo in pairs(args) do
plugins_postrepo(repo, aportsdir, repodest, abuild.arch, stats[repo])
end
-for repo,stat in pairs(stats) do
+for repo, stat in pairs(stats) do
info("%s built:\t%d", repo, stat.built)
info("%s tried:\t%d", repo, stat.tried)
info("%s deleted:\t%d", repo, stat.deleted)