summaryrefslogtreecommitdiffstats
path: root/buildrepo.lua
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2015-07-22 15:57:35 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2015-07-22 15:57:35 +0200
commitace87a06e5782b6f7f2235094f32847fe836ea15 (patch)
tree8eecf42967e8be79a4d04c7a3c56225d8258e9c6 /buildrepo.lua
parent642ac28b08014799c9db6920a26902cb27bda2b5 (diff)
downloadlua-aports-ace87a06e5782b6f7f2235094f32847fe836ea15.tar.bz2
lua-aports-ace87a06e5782b6f7f2235094f32847fe836ea15.tar.xz
buildrepo: add support for plugins.d
Make it possible to add hooks that are execute pre and post build. This can be used for posting build error messages, copying build logs etc.
Diffstat (limited to 'buildrepo.lua')
-rwxr-xr-xbuildrepo.lua34
1 files changed, 29 insertions, 5 deletions
diff --git a/buildrepo.lua b/buildrepo.lua
index bc0a784..4fb9f12 100755
--- a/buildrepo.lua
+++ b/buildrepo.lua
@@ -4,6 +4,8 @@ local abuild = require("aports.abuild")
local apkrepo = require("aports.apkrepo")
local lfs = require("lfs")
+local pluginsdir = "/etc/buildrepo/plugins.d"
+
local function warn(formatstr, ...)
io.stderr:write(("WARNING: %s\n"):format(formatstr:format(...)))
io.stderr:flush()
@@ -75,6 +77,26 @@ local function skip_aport(aport)
return true
end
+local function run_plugins(dirpath, func, ...)
+ local a = lfs.attributes(dirpath)
+ if a == nil or a.mode ~= "directory" then
+ return
+ end
+ local flist = {}
+ for f in lfs.dir(dirpath) do
+ if string.match(f, ".lua$") then
+ table.insert(flist, f)
+ end
+ end
+ table.sort(flist)
+ for i = 1,#flist do
+ local m = dofile(dirpath.."/"..flist[i])
+ if type(m[func]) == "function" then
+ m[func](...)
+ end
+ end
+end
+
local function build_aport(aport, repodest, logdir)
local success, errmsg = lfs.chdir(aport.dir)
if not success then
@@ -92,10 +114,16 @@ local function build_aport(aport, repodest, logdir)
logredirect = ("> '%s' 2>&1"):format(logfile)
end
local cmd = ("REPODEST='%s' abuild -r -m %s"):format(repodest, logredirect)
- success = os.execute(cmd)
+ run_plugins(pluginsdir, "prebuild", aport, logfile)
+ if opts.n then
+ success = true
+ else
+ success = os.execute(cmd)
+ end
if not success then
err("%s: Failed to build", aport.pkgname)
end
+ run_plugins(pluginsdir, "postbuild", aport, success, logfile)
return success
end
@@ -136,10 +164,6 @@ aportsdir = opts.a or ("%s/aports"):format(homedir)
repodest = opts.d or abuild.repodest or ("%s/packages"):format(homedir)
logdirbase = opts.l
-if opts.n then
- build_aport = function() return true end
-end
-
stats = {}
for _,repo in pairs(args) do
local db = require('aports.db').new(aportsdir, repo)