]> git.ipfire.org Git - pakfire.git/commitdiff
build: Refactor reading the makefile
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Aug 2022 21:07:23 +0000 (21:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Aug 2022 21:19:13 +0000 (21:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index f4beaee63aba67eac1840075962a937c129b0292..f6aa43f1df4aeeace0884755413ce0948d8a091a 100644 (file)
@@ -1209,11 +1209,51 @@ static int pakfire_build_init(struct pakfire_build* build) {
        return 0;
 }
 
+static int pakfire_build_read_makefile(struct pakfire_build* build,
+               struct pakfire_parser** parser, struct pakfire_package* package) {
+       char makefile[PATH_MAX];
+       char path[PATH_MAX];
+       int r;
+
+       struct pakfire_parser_error* error = NULL;
+
+       const char* nevra = pakfire_package_get_nevra(package);
+       const char* name  = pakfire_package_get_name(package);
+
+       // Compose path to makefile
+       r = pakfire_string_format(makefile, "/usr/src/packages/%s/%s.nm", nevra, name);
+       if (r < 0)
+               return 1;
+
+       // Make it absolute
+       r = pakfire_make_path(build->pakfire, path, makefile);
+       if (r < 0)
+               return 1;
+
+       // Read makefile
+       r = pakfire_read_makefile(parser, build->pakfire, path, &error);
+       if (r) {
+               if (error) {
+                       ERROR(build->pakfire, "Could not parse makefile %s: %s\n", path,
+                               pakfire_parser_error_get_message(error));
+               } else {
+                       ERROR(build->pakfire, "Could not parse makefile %s: %m\n", path);
+               }
+
+               goto ERROR;
+       }
+
+ERROR:
+       if (error)
+               pakfire_parser_error_unref(error);
+
+       return r;
+}
+
 PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* path) {
        struct pakfire_archive* archive = NULL;
        struct pakfire_package* package = NULL;
-
-       char makefile[PATH_MAX];
+       struct pakfire_parser* makefile = NULL;
        int r;
 
        // Open source archive
@@ -1230,9 +1270,7 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p
                goto ERROR;
        }
 
-       // Fetch some information
        const char* nevra = pakfire_package_get_nevra(package);
-       const char* name  = pakfire_package_get_name(package);
 
        INFO(build->pakfire, "Building %s...\n", nevra);
 
@@ -1253,21 +1291,23 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p
                goto ERROR;
        }
 
-       // Compose path to makefile
-       r = pakfire_string_format(makefile, "/usr/src/packages/%s/%s.nm", nevra, name);
-       if (r < 0) {
-               ERROR(build->pakfire, "Could not compose makefile path: %m\n");
+       // Open the makefile
+       r = pakfire_build_read_makefile(build, &makefile, package);
+       if (r)
                goto ERROR;
-       }
 
+#if 0
        // Run build
        r = pakfire_build_makefile(build, makefile);
        if (r) {
                ERROR(build->pakfire, "Could not build %s: %m\n", nevra);
                goto ERROR;
        }
+#endif
 
 ERROR:
+       if (makefile)
+               pakfire_parser_unref(makefile);
        if (archive)
                pakfire_archive_unref(archive);
        if (package)