]> git.ipfire.org Git - pakfire.git/commitdiff
build: Add logging_callback
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 22 May 2021 15:19:24 +0000 (15:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 22 May 2021 15:19:24 +0000 (15:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/build.c
src/libpakfire/include/pakfire/build.h
src/pakfire/builder.py

index 2df99d125b97d1bcfe8aaec8c9a55903f7f91159..d7d5edbbb011812cb8eff727846077a5a55e71f0 100644 (file)
@@ -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);
 }
index 40e65a7e23306fc373c4ab436dca60e443e26b03..ca658f483f4ecc0fa14f75d046519b540d673325 100644 (file)
@@ -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)
index 8708d43a09ae84930fc9b82c4c432703d258c595..8fb99d3672a6244ac4160c2e9cb2233a61ee5579 100644 (file)
 #ifndef PAKFIRE_BUILD_H
 #define PAKFIRE_BUILD_H
 
+#include <pakfire/execute.h>
 #include <pakfire/types.h>
 
 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 */
index 2b90e6db0c05d626acc411fb7e37318428d8a548..6c39d9824dfe450dbebbe007bf376ca1af6892a5 100644 (file)
@@ -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