#include "errors.h"
#include "key.h"
#include "pakfire.h"
+#include "parser.h"
#include "repo.h"
#include "util.h"
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",
METH_VARARGS,
NULL
},
+ {
+ "read_makefile",
+ (PyCFunction)Pakfire_read_makefile,
+ METH_VARARGS,
+ NULL
+ },
{
"search",
(PyCFunction)Pakfire_search,
#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 */
#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);
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>
pakfire_get_pool;
pakfire_get_repo;
pakfire_make_path;
+ pakfire_read_makefile;
pakfire_ref;
pakfire_search;
pakfire_set_cache_path;
#include <ctype.h>
#include <errno.h>
#include <ftw.h>
+#include <glob.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#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>
// 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;
+}
# Run the transaction
transaction.run()
- def build(self, package, shell=True):
+ def build(self, path, shell=True):
# Install build environment
packages = [
"@Build",
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:
# 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 = []