]> git.ipfire.org Git - pakfire.git/commitdiff
builder: Implement reading makefiles
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 1 Mar 2021 16:46:22 +0000 (16:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 1 Mar 2021 16:46:22 +0000 (16:46 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/include/pakfire/constants.h
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/libpakfire.sym
src/libpakfire/pakfire.c
src/pakfire/builder.py

index 5039235642279ec5f03d53442a6838de0d28e5b9..68a7663305bfc13be583b331f715545159023587 100644 (file)
@@ -33,6 +33,7 @@
 #include "errors.h"
 #include "key.h"
 #include "pakfire.h"
+#include "parser.h"
 #include "repo.h"
 #include "util.h"
 
@@ -536,6 +537,43 @@ static PyObject* Pakfire_execute(PakfireObject* self, PyObject* args, PyObject*
        Py_RETURN_NONE;
 }
 
+static PyObject* Pakfire_read_makefile(PakfireObject* self, PyObject* args) {
+       const char* path = NULL;
+
+       if (!PyArg_ParseTuple(args, "s", &path))
+               return NULL;
+
+       PakfireParser parser = NULL;
+       struct pakfire_parser_error* error = NULL;
+
+       int r = pakfire_read_makefile(&parser, self->pakfire, path, &error);
+
+       // The parser could not parse the makefile
+       if (r == 1) {
+               PyErr_SetString(PyExc_SyntaxError, pakfire_parser_error_get_message(error));
+               PyErr_SyntaxLocation(
+                       pakfire_parser_error_get_filename(error),
+                       pakfire_parser_error_get_line(error)
+               );
+               return NULL;
+
+       // Handle any other internal error
+       } else if (r < 0) {
+               PyErr_SetFromErrno(PyExc_OSError);
+               return NULL;
+       }
+
+       PyObject* ret = new_parser(parser);
+       if (!ret)
+               return NULL;
+
+       pakfire_parser_unref(parser);
+       if (error)
+               pakfire_parser_error_unref(error);
+
+       return ret;
+}
+
 static struct PyMethodDef Pakfire_methods[] = {
        {
                "execute",
@@ -573,6 +611,12 @@ static struct PyMethodDef Pakfire_methods[] = {
                METH_VARARGS,
                NULL
        },
+       {
+               "read_makefile",
+               (PyCFunction)Pakfire_read_makefile,
+               METH_VARARGS,
+               NULL
+       },
        {
                "search",
                (PyCFunction)Pakfire_search,
index 9404b3a3aaff9cb20dbb861526d237d986f3b087..a6bef7260fae64d054072cd6493c4b89ee7489d4 100644 (file)
@@ -27,4 +27,7 @@
 
 #define CACHE_PATH "/var/cache/pakfire"
 
+#define PAKFIRE_MACROS_DIR                             "/usr/lib/pakfire/macros"
+#define PAKFIRE_MACROS_GLOB_PATTERN            PAKFIRE_MACROS_DIR "/*.macro"
+
 #endif /* PAKFIRE_CONSTANTS_H */
index c433cda48bcb4bf2a15ab97911517fefd502dc20..2fd2df5d4a5c12c1461a35d47aeae7fbcb17a8ee 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/stat.h>
 #include <time.h>
 
+#include <pakfire/parser.h>
 #include <pakfire/types.h>
 
 int pakfire_create(Pakfire* pakfire, const char* path, const char* arch);
@@ -77,6 +78,11 @@ void pakfire_log_set_function(Pakfire pakfire, pakfire_log_function_t log_functi
 int pakfire_log_get_priority(Pakfire pakfire);
 void pakfire_log_set_priority(Pakfire pakfire, int priority);
 
+// Build
+
+int pakfire_read_makefile(PakfireParser* parser, Pakfire pakfire, const char* path,
+       struct pakfire_parser_error** error);
+
 #ifdef PAKFIRE_PRIVATE
 
 #include <solv/pool.h>
index 905c9a0fb5f8154f76cebc9998252908e8eb0d02..69a17d3290a97c7abdd2b79fe97304d0b78ccd3e 100644 (file)
@@ -37,6 +37,7 @@ global:
        pakfire_get_pool;
        pakfire_get_repo;
        pakfire_make_path;
+       pakfire_read_makefile;
        pakfire_ref;
        pakfire_search;
        pakfire_set_cache_path;
index efd9acf47d9dc9ba122ffcc27565c66ed75a14d0..824c2c6ec6346be09c17790ef79053ee59457c8c 100644 (file)
@@ -21,6 +21,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <ftw.h>
+#include <glob.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -43,6 +44,7 @@
 #include <pakfire/package.h>
 #include <pakfire/packagelist.h>
 #include <pakfire/pakfire.h>
+#include <pakfire/parser.h>
 #include <pakfire/private.h>
 #include <pakfire/repo.h>
 #include <pakfire/types.h>
@@ -773,3 +775,74 @@ 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);
+       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;
+}
index 438714588f1e3845d09c01ff9d2c99965cb91d2a..e4583b0837153abb96230ee5da9652a6a849e126 100644 (file)
@@ -317,7 +317,7 @@ class BuilderContext(object):
                        # Run the transaction
                        transaction.run()
 
-       def build(self, package, shell=True):
+       def build(self, path, shell=True):
                # Install build environment
                packages = [
                        "@Build",
@@ -328,7 +328,10 @@ class BuilderContext(object):
                        packages.append("ccache")
 
                # Open the package archive
-               archive = _pakfire.Archive(self.pakfire, package)
+               archive = _pakfire.Archive(self.pakfire, path)
+
+               # Parse all metadata
+               package = archive.get_package()
 
                requires = archive.get("dependencies.requires")
                if requires:
@@ -339,7 +342,13 @@ class BuilderContext(object):
 
                # Extract the source archive (if we have one)
                if archive:
-                       archive.extract("%s/build" % self.pakfire.path)
+                       archive.extract("%s/usr/src" % self.pakfire.path)
+
+               # Read the makefile
+               makefile = self.pakfire.read_makefile("%s/usr/src/%s/%s.nm" \
+                       % (self.pakfire.path, package, package.name))
+
+               print(makefile)
 
        def shell(self, packages=[], install=None):
                archives = []