]> git.ipfire.org Git - pakfire.git/commitdiff
Move pakfire_read_makefile to dist
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 13 Mar 2021 18:03:09 +0000 (18:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 13 Mar 2021 18:03:09 +0000 (18:03 +0000)
It fits better here

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/dist.c
src/libpakfire/include/pakfire/constants.h
src/libpakfire/pakfire.c

index a7f46ed9497ce3785b8d2fd44bbfec4076cf273e..f7c5f06bed095b87deca39d53874071a4080ef53 100644 (file)
@@ -22,6 +22,7 @@
 #include <fts.h>
 #include <dirent.h>
 #include <fcntl.h>
+#include <glob.h>
 #include <stddef.h>
 #include <stdlib.h>
 
 #include <pakfire/types.h>
 #include <pakfire/util.h>
 
+#define PAKFIRE_MACROS_DIR                             "/usr/lib/pakfire/macros"
+#define PAKFIRE_MACROS_GLOB_PATTERN            PAKFIRE_MACROS_DIR "/*.macro"
+
+PAKFIRE_EXPORT int pakfire_read_makefile(PakfireParser* parser, Pakfire pakfire,
+               const char* path, struct pakfire_parser_error** error) {
+       int r = 1;
+
+       *parser = pakfire_parser_create(pakfire, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS);
+       if (!*parser) {
+               r = 1;
+               goto ERROR;
+       }
+
+       // XXX set defaults
+
+       // Find all macros
+       char* macros = pakfire_make_path(pakfire, PAKFIRE_MACROS_GLOB_PATTERN);
+       if (!macros)
+               goto ERROR;
+
+       DEBUG(pakfire, "Searching for macros in %s\n", macros);
+
+       glob_t globmacros;
+       r = glob(macros, 0, NULL, &globmacros);
+       free(macros);
+
+       // Handle any errors
+       switch (r) {
+               case 0:
+               case GLOB_NOMATCH:
+                       break;
+
+               case GLOB_NOSPACE:
+                       errno = ENOMEM;
+                       goto ERROR;
+
+               case GLOB_ABORTED:
+                       goto ERROR;
+
+               default:
+                       ERROR(pakfire, "glob() returned an unhandled error: %d\n", r);
+                       goto ERROR;
+       }
+
+       DEBUG(pakfire, "Found %zu macro(s)\n", globmacros.gl_pathc);
+
+       // Read all macros
+       for (unsigned int i = 0; i < globmacros.gl_pathc; i++) {
+               // Parse the file
+               r = pakfire_parser_read_file(*parser, globmacros.gl_pathv[i], error);
+               if (r)
+                       goto ERROR;
+       }
+
+       globfree(&globmacros);
+
+       // Finally, parse the makefile
+       r = pakfire_parser_read_file(*parser, path, error);
+       if (r)
+               goto ERROR;
+
+       return 0;
+
+ERROR:
+       globfree(&globmacros);
+
+       if (*parser) {
+               pakfire_parser_unref(*parser);
+               *parser = NULL;
+       }
+
+       return r;
+}
+
 static int pakfire_dist_download_source(Pakfire pakfire, const char* filename,
                const char* cache_path) {
        struct pakfire_downloader* downloader;
index d8d1c85f2b63609a6ce626ad3e660d0cb9fa26b4..d4870eef266fb3cd929a453469b7fc2b3cd37834 100644 (file)
@@ -33,9 +33,6 @@
 
 #define CACHE_PATH "/var/cache/pakfire"
 
-#define PAKFIRE_MACROS_DIR                             "/usr/lib/pakfire/macros"
-#define PAKFIRE_MACROS_GLOB_PATTERN            PAKFIRE_MACROS_DIR "/*.macro"
-
 #ifdef PAKFIRE_PRIVATE
 
 // The file format that this version generates
index b63325268587d05c2cfc5c33e3480c3678f72203..a5eb1f0150dcfd488a08287e650bbaa813a846e2 100644 (file)
@@ -21,7 +21,6 @@
 #include <ctype.h>
 #include <errno.h>
 #include <ftw.h>
-#include <glob.h>
 #include <linux/limits.h>
 #include <stddef.h>
 #include <stdio.h>
@@ -776,74 +775,3 @@ PAKFIRE_EXPORT void pakfire_log(Pakfire pakfire, int priority, const char* file,
        // Restore errno
        errno = saved_errno;
 }
-
-PAKFIRE_EXPORT int pakfire_read_makefile(PakfireParser* parser, Pakfire pakfire,
-               const char* path, struct pakfire_parser_error** error) {
-       int r = 1;
-
-       *parser = pakfire_parser_create(pakfire, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS);
-       if (!*parser) {
-               r = 1;
-               goto ERROR;
-       }
-
-       // XXX set defaults
-
-       // Find all macros
-       char* macros = pakfire_make_path(pakfire, PAKFIRE_MACROS_GLOB_PATTERN);
-       if (!macros)
-               goto ERROR;
-
-       DEBUG(pakfire, "Searching for macros in %s\n", macros);
-
-       glob_t globmacros;
-       r = glob(macros, 0, NULL, &globmacros);
-       free(macros);
-
-       // Handle any errors
-       switch (r) {
-               case 0:
-               case GLOB_NOMATCH:
-                       break;
-
-               case GLOB_NOSPACE:
-                       errno = ENOMEM;
-                       goto ERROR;
-
-               case GLOB_ABORTED:
-                       goto ERROR;
-
-               default:
-                       ERROR(pakfire, "glob() returned an unhandled error: %d\n", r);
-                       goto ERROR;
-       }
-
-       DEBUG(pakfire, "Found %zu macro(s)\n", globmacros.gl_pathc);
-
-       // Read all macros
-       for (unsigned int i = 0; i < globmacros.gl_pathc; i++) {
-               // Parse the file
-               r = pakfire_parser_read_file(*parser, globmacros.gl_pathv[i], error);
-               if (r)
-                       goto ERROR;
-       }
-
-       globfree(&globmacros);
-
-       // Finally, parse the makefile
-       r = pakfire_parser_read_file(*parser, path, error);
-       if (r)
-               goto ERROR;
-
-       return 0;
-
-ERROR:
-       globfree(&globmacros);
-
-       if (*parser) {
-               pakfire_parser_unref(*parser);
-               *parser = NULL;
-       }
-
-       return r;
-}