From: Michael Tremer Date: Mon, 31 Oct 2022 18:13:59 +0000 (+0000) Subject: build: Perform an installation test after the build X-Git-Tag: 0.9.28~166 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ad8d09bd7b87409ba0e5c486350a7557a633ff8;p=pakfire.git build: Perform an installation test after the build 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 --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 2a94f7cbb..08977a61f 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -37,10 +37,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -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; }