#include <pakfire/errno.h>
#include <pakfire/execute.h>
#include <pakfire/logging.h>
+#include <pakfire/package.h>
#include <pakfire/parser.h>
#include <pakfire/pakfire.h>
#include <pakfire/private.h>
return 0;
}
+PAKFIRE_EXPORT int pakfire_parser_create_package(PakfireParser parser,
+ PakfirePackage* pkg, PakfireRepo repo, const char* namespace) {
+ int r = 1;
+
+ char* name = NULL;
+ char* epoch = NULL;
+ char* version = NULL;
+ char* release = NULL;
+ char* arch = NULL;
+ char* evr = NULL;
+
+ // Fetch name
+ name = pakfire_parser_get(parser, namespace, "name");
+ if (!name) {
+ ERROR(parser->pakfire, "Name is empty\n");
+ goto CLEANUP;
+ }
+
+ // Fetch epoch
+ epoch = pakfire_parser_get(parser, namespace, "epoch");
+ if (!epoch) {
+ ERROR(parser->pakfire, "Epoch is empty\n");
+ goto CLEANUP;
+ }
+
+ // Fetch version
+ version = pakfire_parser_get(parser, namespace, "version");
+ if (!version) {
+ ERROR(parser->pakfire, "Version is empty\n");
+ goto CLEANUP;
+ }
+
+ // Fetch release
+ release = pakfire_parser_get(parser, namespace, "release");
+ if (!release) {
+ ERROR(parser->pakfire, "Release is empty\n");
+ goto CLEANUP;
+ }
+
+ // Fetch arch
+ arch = pakfire_parser_get(parser, namespace, "arch");
+ if (!arch) {
+ ERROR(parser->pakfire, "Arch is empty\n");
+ goto CLEANUP;
+ }
+
+ // Compile EVR
+ evr = pakfire_package_join_evr(epoch, version, release);
+ if (!evr)
+ goto CLEANUP;
+
+ // Create a new package object
+ *pkg = pakfire_package_create(parser->pakfire, repo, name, evr, arch);
+ if (!*pkg) {
+ ERROR(parser->pakfire, "Could not create package\n");
+ goto CLEANUP;
+ }
+
+ // All okay
+ r = 0;
+
+CLEANUP:
+ if (name)
+ free(name);
+ if (epoch)
+ free(epoch);
+ if (version)
+ free(version);
+ if (release)
+ free(release);
+ if (arch)
+ free(arch);
+
+ return r;
+}
+
// Error
struct pakfire_parser_error {
#include <stdlib.h>
#include <string.h>
+#include <pakfire/package.h>
#include <pakfire/parser.h>
+#include <pakfire/repo.h>
#include <pakfire/util.h>
#include "../testsuite.h"
NULL,
};
+static int load_macros(PakfireParser parser) {
+ char* macros = pakfire_path_join(TEST_SRC_PATH, "../macros/*.macro");
+ ASSERT(macros);
+
+ glob_t buffer;
+ int r = glob(macros, 0, NULL, &buffer);
+ ASSERT(r == 0);
+
+ for (unsigned int i = 0; i < buffer.gl_pathc; i++) {
+ r = pakfire_parser_read_file(parser, buffer.gl_pathv[i], NULL);
+ ASSERT(r == 0);
+ }
+
+ free(macros);
+
+ return 0;
+}
+
static int test_parse(const struct test* t) {
const char** makefile = makefiles;
}
static int test_macros(const struct test* t) {
- char* macros = pakfire_path_join(TEST_SRC_PATH, "../macros/*.macro");
- ASSERT(macros);
+ PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0);
+ ASSERT(parser);
- glob_t buffer;
- int r = glob(macros, 0, NULL, &buffer);
- ASSERT(r == 0);
+ // Load 'em all
+ int r = load_macros(parser);
+ if (r)
+ return r;
- PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0);
+ pakfire_parser_unref(parser);
+
+ return EXIT_SUCCESS;
+}
+
+static int test_packages(const struct test* t) {
+ PakfirePackage pkg = NULL;
+
+ PakfireRepo repo = pakfire_repo_create(t->pakfire, "test");
+ ASSERT(repo);
+
+ PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL,
+ PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS);
ASSERT(parser);
- for (unsigned int i = 0; i < buffer.gl_pathc; i++) {
- r = pakfire_parser_read_file(parser, buffer.gl_pathv[i], NULL);
- ASSERT(r == 0);
- }
+ // Load macros
+ int r = load_macros(parser);
+ if (r)
+ return r;
+
+ // Read beep.nm
+ char* path = pakfire_path_join(TEST_SRC_PATH, "data/beep.nm");
+ ASSERT(path);
+ r = pakfire_parser_read_file(parser, path, NULL);
+ ASSERT(r == 0);
+
+ // Create package
+ r = pakfire_parser_create_package(parser, &pkg, repo, NULL);
+ ASSERT(r == 0);
+ ASSERT(pkg);
+
+ // Dump package
+ char* s = pakfire_package_dump(pkg, PAKFIRE_PKG_DUMP_LONG);
+ ASSERT(s);
+
+ printf("%s\n", s);
+
+ // Check name
+ const char* name = pakfire_package_get_name(pkg);
+ ASSERT_STRING_EQUALS(name, "beep");
+
+ // Cleanup
pakfire_parser_unref(parser);
- free(macros);
+ pakfire_package_unref(pkg);
+ pakfire_repo_unref(repo);
+ free(path);
return EXIT_SUCCESS;
}
int main(int argc, char** argv) {
testsuite_add_test(test_macros);
testsuite_add_test(test_parse);
+ testsuite_add_test(test_packages);
return testsuite_run();
}