]> git.ipfire.org Git - pakfire.git/commitdiff
job: Create scaffolding to run a build
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 5 Oct 2024 10:49:56 +0000 (10:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 5 Oct 2024 10:49:56 +0000 (10:49 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/job.c

index 7151ba7df25c81a6e13b63afd42384ce41a4582a..9e5e0a929fb469e5ba022c67f8f7de0f247af4d7 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <systemd/sd-event.h>
 
+#include <pakfire/build.h>
 #include <pakfire/constants.h>
 #include <pakfire/ctx.h>
 #include <pakfire/daemon.h>
@@ -276,6 +277,8 @@ static int pakfire_job_parent(struct pakfire_job* job) {
 
 static int pakfire_job_child(struct pakfire_job* job) {
        struct pakfire* pakfire = NULL;
+       struct pakfire_build* build = NULL;
+       char job_id[UUID_STR_LEN];
        FILE* conf = NULL;
        int r;
 
@@ -284,6 +287,9 @@ static int pakfire_job_child(struct pakfire_job* job) {
 
        CTX_DEBUG(job->ctx, "Launched job child as PID %d\n", pid);
 
+       // Format the job ID as string
+       uuid_unparse(job->job_id, job_id);
+
        // Map the configuration
        conf = fmemopen(job->conf, strlen(job->conf), "r");
        if (!conf) {
@@ -300,13 +306,39 @@ static int pakfire_job_child(struct pakfire_job* job) {
                goto ERROR;
        }
 
-       // XXX TODO
-       for (unsigned int i = 0; i < 5; i++) {
-               printf("WORK\n");
-               sleep(1);
+       int build_flags =
+               PAKFIRE_BUILD_DISABLE_SNAPSHOT |
+               (job->flags & PAKFIRE_JOB_CCACHE) ? 0 : PAKFIRE_BUILD_DISABLE_CCACHE;
+
+       // Create a new build environment
+       r = pakfire_build_create(&build, pakfire, job_id, build_flags);
+       if (r) {
+               CTX_ERROR(job->ctx, "Could not setup the build environment: %m\n");
+               r = -errno;
+               goto ERROR;
+       }
+
+       // Set the ccache path (if set)
+       if (job->flags & PAKFIRE_JOB_CCACHE) {
+               if (*job->ccache_path) {
+                       // XXX THIS NEEDS TO BE PREFIXED WITH THE BASE PATH
+                       r = pakfire_build_set_ccache_path(build, job->ccache_path);
+                       if (r) {
+                               CTX_ERROR(job->ctx, "Could not set ccache path: %m\n");
+                               r = -errno;
+                               goto ERROR;
+                       }
+               }
        }
 
+       // XXX need to set target
+
+       // Run the build
+       r = pakfire_build_exec(build, job->pkg);
+
 ERROR:
+       if (build)
+               pakfire_build_unref(build);
        if (pakfire)
                pakfire_unref(pakfire);
        if (conf)