diff options
-rw-r--r-- | Makefile | 13 | ||||
-rwxr-xr-x | ap.in | 200 | ||||
-rwxr-xr-x | aports.lua | 298 |
3 files changed, 3 insertions, 508 deletions
@@ -8,12 +8,8 @@ sysconfdir ?= /etc datadir ?= $(prefix)/share/$(PACKAGE) abuildrepo ?= ~/.cache/abuild -LUA_VERSION = 5.2 -LUA_SHAREDIR ?= $(prefix)/share/lua/$(LUA_VERSION)/ -LUA_SHEBANG ?= /usr/bin/lua$(LUA_VERSION) - SCRIPTS := abuild buildrepo abuild-keygen abuild-sign newapkbuild \ - abump apkgrel ap buildlab apkbuild-cpan checkapk + abump apkgrel buildlab apkbuild-cpan checkapk USR_BIN_FILES := $(SCRIPTS) abuild-tar abuild-sudo SAMPLES := sample.APKBUILD sample.initd sample.confd \ sample.pre-install sample.post-install @@ -38,8 +34,7 @@ SED_REPLACE := -e 's:@VERSION@:$(FULL_VERSION):g' \ -e 's:@prefix@:$(prefix):g' \ -e 's:@sysconfdir@:$(sysconfdir):g' \ -e 's:@datadir@:$(datadir):g' \ - -e 's:@abuildrepo@:$(abuildrepo):g' \ - -e 's:@LUA_SHEBANG@:$(LUA_SHEBANG):g' + -e 's:@abuildrepo@:$(abuildrepo):g' SSL_CFLAGS = $(shell pkg-config --cflags openssl) SSL_LIBS = $(shell pkg-config --libs openssl) @@ -84,7 +79,7 @@ help: @echo "$(P) makefile" @echo "usage: make install [ DESTDIR=<path> ]" -install: $(USR_BIN_FILES) $(SAMPLES) abuild.conf functions.sh aports.lua +install: $(USR_BIN_FILES) $(SAMPLES) abuild.conf functions.sh install -d $(DESTDIR)/$(bindir) $(DESTDIR)/$(sysconfdir) \ $(DESTDIR)/$(datadir) for i in $(USR_BIN_FILES); do\ @@ -100,8 +95,6 @@ install: $(USR_BIN_FILES) $(SAMPLES) abuild.conf functions.sh aports.lua cp $(SAMPLES) $(DESTDIR)/$(prefix)/share/abuild/ cp $(AUTOTOOLS_TOOLCHAIN_FILES) $(DESTDIR)/$(prefix)/share/abuild/ cp functions.sh $(DESTDIR)/$(datadir)/ - mkdir -p $(DESTDIR)$(LUA_SHAREDIR) - cp aports.lua $(DESTDIR)$(LUA_SHAREDIR)/ .gitignore: Makefile echo "*.tar.bz2" > $@ @@ -1,200 +0,0 @@ -#!@LUA_SHEBANG@ - -aports = require("aports") -lfs = require("lfs") - -local db - -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 ----------------------- -subcmd = {} -subcmd.revdep = { - desc = "Print reverse dependencies", - usage = "PKG...", - run = function(opts) - local i - for i = 1, #opts do - db:foreach_revdep(opts[i], function (k,p) - print(p.pkgname) - end) - end - end -} - -subcmd.list = { - desc = "Print all packages built from aports tree", - usage = "", - run = function() - db:foreach(function (k) - print(k) - end) - end -} - -subcmd.recursdeps = { - desc = "Recursively print all make dependencies for given packages", - usage = "PKG...", - run = function (opts) - for i = 1, #opts do - db:recurs_until(opts[i], function(pn) - print(pn) - end) - end - end -} - -subcmd.builddirs = { - desc = "Print the build dirs for given packages in build order", - usage = "PKG...", - run = function(opts) - local i, p, _ - local visited = {} - local to_print = {} - for i = 1, #opts do - db:foreach_pkg(opts[i], function(_, p) - to_print[p.dir] = true - end) - end - for i = 1, #opts do - db:recurs_until(opts[i], function(pn) - local j,p - db:foreach_pkg(pn, function(j, p) - if to_print[p.dir] then - print(p.dir) - to_print[p.dir] = nil - end - end) - end) - end - end -} - -subcmd.sources = { - desc = "List sources", - usage = "PKG...", - run = function(opts) - local i, p, _ - for i = 1, #opts do - 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 -} - -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 -} - -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 -} - -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 -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 = table.remove(opts, 1) - -if cmd == nil then - print_usage() - -- usage - return -end - -if #repodirs == 0 then - if lfs.attributes("APKBUILD") then - repodirs[1] = string.gsub(lfs.currentdir(), "(.*)/.*", "%1") - else - repodirs[1] = lfs.currentdir() - end -end - -if subcmd[cmd] and type(subcmd[cmd].run) == "function" then - db = aports.new(repodirs) - loadtime = os.clock() - subcmd[cmd].run(opts) - runtime = os.clock() - loadtime --- io.stderr:write("db load time = "..tostring(loadtime).."\n") --- io.stderr:write("cmd run time = "..tostring(runtime).."\n") -else - io.stderr:write(cmd..": invalid subcommand\n") -end - diff --git a/aports.lua b/aports.lua deleted file mode 100755 index 823fc8a..0000000 --- a/aports.lua +++ /dev/null @@ -1,298 +0,0 @@ -module(..., package.seeall) - -abuild_conf_file = "/etc/abuild.conf" -abuild_functions = "/usr/share/abuild/functions.sh" - -local abuild_conf = {} - -function get_abuild_conf(var) - -- check cache - if abuild_conf[var] ~= nil then - return abuild_conf[var] - end - - -- use os env var - abuild_conf[var] = os.getenv(var) - if abuild_conf[var] ~= nil then - return abuild_conf[var] - end - - -- parse config file - local f = io.popen(" . "..abuild_conf_file..' ; echo -n "$'..var..'"') - abuild_conf[var] = f:read("*all") - f:close() - return abuild_conf[var] -end - -local function split_subpkgs(str) - local t = {} - local e - if (str == nil) then - return nil - end - for e in string.gmatch(str, "%S+") do - t[#t + 1] = string.gsub(e, ":.*", "") - end - return t -end - -local function split(str) - local t = {} - local e - if (str == nil) then - return nil - end - for e in string.gmatch(str, "%S+") do - t[#t + 1] = e - end - return t -end - -local function split_apkbuild(line) - local r = {} - local dir,pkgname, pkgver, pkgrel, arch, depends, makedepends, subpackages, source, url = string.match(line, "([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)|([^|]*)") - r.dir = dir - r.pkgname = pkgname - r.pkgver = pkgver - r.pkgrel = pkgrel - r.depends = split(depends) - r.makedepends = split(makedepends) - r.subpackages = split_subpkgs(subpackages) - r.source = split(source) - r.url = url - return r -end - --- parse the APKBUILDs and return an iterator -local function parse_apkbuilds(dirs) - local i,v, p - local str="" - if dirs == nil then - return nil - end - --expand repos - for i,v in ipairs(dirs) do - str = str..v.."/*/APKBUILD " - end - - local p = io.popen(". "..abuild_functions..";"..[[ - for i in ]]..str..[[; do - pkgname= - pkgver= - pkgrel= - arch= - depends= - makedepends= - subpackages= - source= - url= - dir="${i%/APKBUILD}"; - [ -n "$dir" ] || exit 1; - cd "$dir"; - . ./APKBUILD; - echo $dir\|$pkgname\|$pkgver\|$pkgrel\|$arch\|$depends\|$makedepends\|$subpackages\|$source\|$url ; - done; - ]]) - return function() - local line = p:read("*line") - if line == nil then - p:close() - return nil - end - return split_apkbuild(line) - end -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 is_remote(url) - local _,pref - for _,pref in pairs{ "^http://", "^ftp://", "^https://", ".*::.*" } do - if string.match(url, pref) then - return true - end - end - return false -end - --- iterate over all entries in source and execute the function for remote -function foreach_remote_source(p, func) - local _,s - if p == nil or type(p.source) ~= "table" then - return - end - for _,url in pairs(p.source) do - if is_remote(url) then - func(url) - end - end -end - -function get_maintainer(pkg) - if pkg == nil or pkg.dir == nil then - return nil - end - local f = io.open(pkg.dir.."/APKBUILD") - if f == nil then - return nil - end - local line - for line in f:lines() do - local maintainer = line:match("^%s*#%s*Maintainer:%s*(.*)") - if maintainer then - f:close() - return maintainer - end - end - f:close() - return nil -end - -function get_repo_name(pkg) - if pkg == nil or pkg.dir == nil then - return nil - end - return string.match(pkg.dir, ".*/(.*)/.*") -end - -function get_apk_filename(pkg) - return pkg.pkgname.."-"..pkg.pkgver.."-r"..pkg.pkgrel..".apk" -end - -function get_apk_file_path(pkg) - local pkgdest = get_abuild_conf("PKGDEST") - if pkgdest ~= nil and pkgdest ~= "" then - return pkgdest.."/"..get_apk_filename(pkg) - end - local repodest = get_abuild_conf("REPODEST") - if repodest ~= nil and repodest ~= "" then - local arch = get_abuild_conf("CARCH") - return repodest.."/"..get_repo_name(pkg).."/"..arch.."/"..get_apk_filename(pkg) - end - return pkg.dir.."/"..get_apk_filename(pkg) -end - - -local function init_apkdb(repodirs) - local pkgdb = {} - local revdeps = {} - local a - for a in parse_apkbuilds(repodirs) do - -- io.write(a.pkgname.." "..a.pkgver.."\t"..a.dir.."\n") - if pkgdb[a.pkgname] == nil then - pkgdb[a.pkgname] = {} - end - a.all_deps = all_deps - table.insert(pkgdb[a.pkgname], a) - -- add subpackages to package db - local k,v - for k,v in pairs(a.subpackages) do - if pkgdb[v] == nil then - pkgdb[v] = {} - end - table.insert(pkgdb[v], a) - end - -- add to reverse dependencies - for v in pairs(all_deps(a)) do - if revdeps[v] == nil then - revdeps[v] = {} - end - table.insert(revdeps[v], a) - end - end - return pkgdb, revdeps -end - -local Aports = {} -function Aports:recurs_until(pn, func) - local visited={} - local apkdb = self.apks - 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 - -function Aports:target_packages(pkgname) - local i,v - local t = {} - for k,v in pairs(self.apks[pkgname]) do - table.insert(t, pkgname.."-"..v.pkgver.."-r"..v.pkgrel..".apk") - end - return t -end - -function Aports:foreach(f) - local k,v - for k,v in pairs(self.apks) do - f(k,v) - end -end - -function Aports:foreach_revdep(pkg, f) - local k,v - for k,v in pairs(self.revdeps[pkg] or {}) do - f(k,v) - end -end - -function Aports:foreach_pkg(pkg, f) - local k,v - if self.apks[pkg] == nil then - io.stderr:write("WARNING: "..pkg.." has no data\n") - end - for k,v in pairs(self.apks[pkg]) do - f(k,v) - end -end - -function Aports:foreach_aport(f) - self:foreach(function(pkgname) - self:foreach_pkg(pkgname, function(i, pkg) - if pkgname == pkg.pkgname then - f(pkg) - end - end) - end) -end - -function new(repodirs) - local h = Aports - h.repodirs = repodirs - h.apks, h.revdeps = init_apkdb(repodirs) - return h -end - |