From: Michael Tremer Date: Wed, 17 Aug 2022 21:07:23 +0000 (+0000) Subject: build: Refactor reading the makefile X-Git-Tag: 0.9.28~461 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e57188c009322991e1116b9b03344c63b62a0c7d;p=pakfire.git build: Refactor reading the makefile Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index f4beaee63..f6aa43f1d 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -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)