aboutsummaryrefslogtreecommitdiffstats
path: root/main/lua-aports/0001-buildrepo-add-support-for-plugins.d.patch
blob: d7c78e1e85d8fc87320fb2c9dd59df6fe63bb61a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From ace87a06e5782b6f7f2235094f32847fe836ea15 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 22 Jul 2015 15:57:35 +0200
Subject: [PATCH 1/2] 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.
---
 buildrepo.lua | 34 +++++++++++++++++++++++++++++-----
 1 file 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)
-- 
2.4.6