From: Michael Tremer Date: Sat, 22 May 2021 15:19:24 +0000 (+0000) Subject: build: Add logging_callback X-Git-Tag: 0.9.28~1285^2~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d9996005f2fe70b90270463ba869a64fa681225;p=pakfire.git build: Add logging_callback Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 2df99d125..d7d5edbbb 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -844,12 +844,14 @@ static PyObject* execute_return_value(int r) { } static PyObject* Pakfire_build(PakfireObject* self, PyObject* args, PyObject* kwargs) { - char* kwlist[] = {"path", "interactive", NULL}; + char* kwlist[] = {"path", "logging_callback", "interactive", NULL}; const char* path = NULL; + PyObject* logging_callback = NULL; int interactive = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|p", kwlist, &path, &interactive)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|Op", kwlist, &path, + &logging_callback, &interactive)) return NULL; int flags = 0; @@ -858,8 +860,18 @@ static PyObject* Pakfire_build(PakfireObject* self, PyObject* args, PyObject* kw if (interactive) flags |= PAKFIRE_BUILD_INTERACTIVE; + // Check if logging_callback is + if (logging_callback && !PyCallable_Check(logging_callback)) { + PyErr_SetString(PyExc_TypeError, "logging_callback must be callable\n"); + return NULL; + } + + // Set logging callback + Pakfire_execute_logging_callback = logging_callback; + // Run build - int r = pakfire_build(self->pakfire, path, NULL, flags); + int r = pakfire_build(self->pakfire, path, NULL, flags, + (logging_callback) ? __Pakfire_execute_logging_callback : NULL, NULL); return execute_return_value(r); } diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 40e65a7e2..ca658f483 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -48,7 +48,8 @@ static const char* stages[] = { "\n" \ "exit 0\n" -static int pakfire_build_stage(Pakfire pakfire, PakfireParser makefile, const char* stage) { +static int pakfire_build_stage(Pakfire pakfire, PakfireParser makefile, const char* stage, + pakfire_execute_logging_callback logging_callback, void* data) { char template[1024]; // Prepare template for this stage @@ -66,7 +67,8 @@ static int pakfire_build_stage(Pakfire pakfire, PakfireParser makefile, const ch INFO(pakfire, "Running build stage '%s'\n", stage); - r = pakfire_execute_script(pakfire, script, strlen(script), NULL, 0, NULL, NULL); + r = pakfire_execute_script(pakfire, script, strlen(script), NULL, 0, + logging_callback, data); if (r) { ERROR(pakfire, "Build stage '%s' failed with status %d\n", stage, r); } @@ -79,7 +81,8 @@ ERROR: } PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path, - const char* target, int flags) { + const char* target, int flags, + pakfire_execute_logging_callback logging_callback, void* data) { PakfireParser makefile = NULL; struct pakfire_parser_error* error = NULL; @@ -100,7 +103,7 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path, // Run through all build stages for (const char** stage = stages; *stage; stage++) { - int r = pakfire_build_stage(pakfire, makefile, *stage); + int r = pakfire_build_stage(pakfire, makefile, *stage, logging_callback, data); if (r) { // Drop to a shell for debugging if (flags & PAKFIRE_BUILD_INTERACTIVE) diff --git a/src/libpakfire/include/pakfire/build.h b/src/libpakfire/include/pakfire/build.h index 8708d43a0..8fb99d367 100644 --- a/src/libpakfire/include/pakfire/build.h +++ b/src/libpakfire/include/pakfire/build.h @@ -21,13 +21,15 @@ #ifndef PAKFIRE_BUILD_H #define PAKFIRE_BUILD_H +#include #include enum pakfire_build_flags { PAKFIRE_BUILD_INTERACTIVE = (1 << 0), }; -int pakfire_build(Pakfire pakfire, const char* path, const char* target, int flags); +int pakfire_build(Pakfire pakfire, const char* path, const char* target, int flags, + pakfire_execute_logging_callback logging_callback, void* data); int pakfire_shell(Pakfire pakfire); #endif /* PAKFIRE_BUILD_H */ diff --git a/src/pakfire/builder.py b/src/pakfire/builder.py index 2b90e6db0..6c39d9824 100644 --- a/src/pakfire/builder.py +++ b/src/pakfire/builder.py @@ -200,7 +200,7 @@ class BuilderContext(object): self._install([path]) for makefile in glob.glob("%s/usr/src/packages/*/*.nm" % self.pakfire.path): - self.pakfire.build(makefile, interactive=shell) + self.pakfire.build(makefile, logging_callback=self.log.log, interactive=shell) def shell(self, packages=[], install=None): # Setup the environment