]> git.ipfire.org Git - pakfire.git/commitdiff
build: Perform an installation test after the build
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 31 Oct 2022 18:13:59 +0000 (18:13 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 31 Oct 2022 18:13:59 +0000 (18:13 +0000)
We will try to install all packages that have been built and log any
errors if that was not possible including potential solutions.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 2a94f7cbbaf766f4ba1b47f04cb0b811f14ed63a..08977a61fb0021f654364d55f0fa2d0423e7aeda 100644 (file)
 #include <pakfire/packager.h>
 #include <pakfire/parser.h>
 #include <pakfire/private.h>
+#include <pakfire/problem.h>
 #include <pakfire/repo.h>
 #include <pakfire/request.h>
 #include <pakfire/scriptlet.h>
 #include <pakfire/snapshot.h>
+#include <pakfire/solution.h>
 #include <pakfire/string.h>
 #include <pakfire/util.h>
 
@@ -1241,6 +1243,95 @@ ERROR:
        return r;
 }
 
+static int pakfire_build_install_package(struct pakfire* pakfire,
+               struct pakfire_package* pkg, void* p) {
+       struct pakfire_request* request = (struct pakfire_request*)p;
+
+       return pakfire_request_install_package(request, pkg);
+}
+
+static int pakfire_build_install_test(struct pakfire_build* build) {
+       struct pakfire_request* request = NULL;
+       struct pakfire_problem* problem = NULL;
+       struct pakfire_solution* solution = NULL;
+       const char* s = NULL;
+       int r;
+
+       // Create a new request
+       r = pakfire_request_create(&request, build->pakfire, 0);
+       if (r)
+               goto ERROR;
+
+       // Add all packages
+       r = pakfire_packagelist_walk(build->packages, pakfire_build_install_package, request);
+
+       // Solve the request
+       r = pakfire_request_solve(request, NULL, NULL);
+       switch (r) {
+               // All okay
+               case 0:
+                       break;
+
+               // Dependency Error
+               case 2:
+                       ERROR(build->pakfire, "Install test failed:\n");
+
+                       // Walk through all problems
+                       for (;;) {
+                               r = pakfire_request_next_problem(request, &problem);
+                               if (r)
+                                       goto ERROR;
+
+                               // There are no more problems
+                               if (!problem)
+                                       break;
+
+                               // Format the problem into something human-readable
+                               s = pakfire_problem_to_string(problem);
+                               if (!s)
+                                       continue;
+
+                               ERROR(build->pakfire, "  * %s\n", s);
+
+                               // Walk through all solutions
+                               for (;;) {
+                                       r = pakfire_problem_next_solution(problem, &solution);
+                                       if (r)
+                                               goto ERROR;
+
+                                       // There are no more solutions
+                                       if (!solution)
+                                               break;
+
+                                       // Format the solution into something human-readable
+                                       s = pakfire_solution_to_string(solution);
+                                       if (!s)
+                                               continue;
+
+                                       ERROR(build->pakfire, "    * %s\n", s);
+                               }
+                       }
+
+                       break;
+
+               // Any other errors
+               default:
+                       goto ERROR;
+       }
+
+ERROR:
+       if (r)
+               ERROR(build->pakfire, "Install test failed: %m\n");
+       if (request)
+               pakfire_request_unref(request);
+       if (problem)
+               pakfire_problem_unref(problem);
+       if (solution)
+               pakfire_solution_unref(solution);
+
+       return r;
+}
+
 static int pakfire_build_post_check(struct pakfire_build* build) {
        int r;
 
@@ -1249,12 +1340,10 @@ static int pakfire_build_post_check(struct pakfire_build* build) {
        if (r)
                return r;
 
-#if 0
        // Perform install test
        r = pakfire_build_install_test(build);
        if (r)
                return r;
-#endif
 
        return 0;
 }