]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Split keys into name and namespace part
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 2 Mar 2021 11:43:56 +0000 (11:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 2 Mar 2021 11:43:56 +0000 (11:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/archive.c
src/_pakfire/parser.c
src/libpakfire/archive.c
src/libpakfire/include/pakfire/archive.h
src/libpakfire/include/pakfire/parser.h
src/libpakfire/parser.c
src/libpakfire/parser/grammar.y
src/pakfire/builder.py
tests/libpakfire/parser.c

index bb052c583d0ec462b898fdd9c9e71e0ca4418211..e8d745150669091eceea9e329efad6a3a5d5fd90 100644 (file)
@@ -175,12 +175,13 @@ static PyObject* Archive_get_package(ArchiveObject* self) {
 }
 
 static PyObject* Archive_get(ArchiveObject* self, PyObject* args) {
+       const char* namespace = NULL;
        const char* key = NULL;
 
-       if (!PyArg_ParseTuple(args, "|s", &key))
+       if (!PyArg_ParseTuple(args, "zs", &namespace, &key))
                return NULL;
 
-       char* value = pakfire_archive_get(self->archive, key);
+       char* value = pakfire_archive_get(self->archive, namespace, key);
 
        if (!value)
                Py_RETURN_NONE;
index 658a7ec7b8cdf5f8d4ef1bb472fc8ed66226b927..b7f774f7bd7d71fe46a4be8675dd578613853bff 100644 (file)
@@ -127,12 +127,32 @@ static PyObject* Parser_read(ParserObject* self, PyObject* args) {
 }
 
 static PyObject* Parser_get(ParserObject* self, PyObject* args) {
+       const char* namespace = NULL;
        const char* key = NULL;
 
-       if (!PyArg_ParseTuple(args, "s", &key))
+       if (!PyArg_ParseTuple(args, "zs", &namespace, &key))
+               return NULL;
+
+       char* value = pakfire_parser_get(self->parser, namespace, key);
+       if (!value) {
+               PyErr_SetFromErrno(PyExc_OSError);
+               return NULL;
+       }
+
+       PyObject* ret = PyUnicode_FromString(value);
+       free(value);
+
+       return ret;
+}
+
+static PyObject* Parser_expand(ParserObject* self, PyObject* args) {
+       const char* namespace = NULL;
+       const char* s = NULL;
+
+       if (!PyArg_ParseTuple(args, "zs", &namespace, &s))
                return NULL;
 
-       char* value = pakfire_parser_get(self->parser, key);
+       char* value = pakfire_parser_expand(self->parser, namespace, s);
        if (!value) {
                PyErr_SetFromErrno(PyExc_OSError);
                return NULL;
@@ -151,6 +171,12 @@ static struct PyMethodDef Parser_methods[] = {
                METH_VARARGS,
                NULL,
        },
+       {
+               "expand",
+               (PyCFunction)Parser_expand,
+               METH_VARARGS,
+               NULL,
+       },
        {
                "get",
                (PyCFunction)Parser_get,
index 515f774d43d3effbc0f35c0b5d55bb6415f56a75..f5e964af306b9b413a7695bb3ee44d18e9f8855a 100644 (file)
@@ -613,8 +613,8 @@ static int pakfire_archive_read_metadata(PakfireArchive archive, struct archive*
        return pakfire_archive_walk(archive, pakfire_archive_read_metadata_entry);
 }
 
-PAKFIRE_EXPORT char* pakfire_archive_get(PakfireArchive archive, const char* key) {
-       return pakfire_parser_get(archive->parser, key);
+PAKFIRE_EXPORT char* pakfire_archive_get(PakfireArchive archive, const char* namespace, const char* key) {
+       return pakfire_parser_get(archive->parser, namespace, key);
 }
 
 static int archive_copy_data(Pakfire pakfire, struct archive* in, struct archive* out) {
@@ -1247,18 +1247,18 @@ PAKFIRE_EXPORT size_t pakfire_archive_get_size(PakfireArchive archive) {
        Copy all metadata from this archive to the package object
 */
 PAKFIRE_EXPORT PakfirePackage pakfire_archive_make_package(PakfireArchive archive, PakfireRepo repo) {
-       char* name = pakfire_archive_get(archive, "package.name");
-       char* type = pakfire_archive_get(archive, "package.type");
+       char* name = pakfire_archive_get(archive, "package", "name");
+       char* type = pakfire_archive_get(archive, "package", "type");
        char* arch = NULL;
 
        // Get arch for source packages
        if (strcmp(type, "binary") == 0) {
-               arch = pakfire_archive_get(archive, "package.arch");
+               arch = pakfire_archive_get(archive, "package", "arch");
        }
 
-       char* e = pakfire_archive_get(archive, "package.epoch");
-       char* v = pakfire_archive_get(archive, "package.version");
-       char* r = pakfire_archive_get(archive, "package.release");
+       char* e = pakfire_archive_get(archive, "package", "epoch");
+       char* v = pakfire_archive_get(archive, "package", "version");
+       char* r = pakfire_archive_get(archive, "package", "release");
        char* evr = pakfire_package_join_evr(e, v, r);
 
        PakfirePackage pkg = pakfire_package_create(
@@ -1289,49 +1289,49 @@ PAKFIRE_EXPORT PakfirePackage pakfire_archive_make_package(PakfireArchive archiv
        }
 
        // Set UUID
-       char* uuid = pakfire_archive_get(archive, "package.uuid");
+       char* uuid = pakfire_archive_get(archive, "package", "uuid");
        if (uuid) {
                pakfire_package_set_uuid(pkg, uuid);
                free(uuid);
        }
 
        // Set groups
-       char* groups = pakfire_archive_get(archive, "package.groups");
+       char* groups = pakfire_archive_get(archive, "package", "groups");
        if (groups) {
                pakfire_package_set_groups(pkg, groups);
                free(groups);
        }
 
        // Set maintainer
-       char* maintainer = pakfire_archive_get(archive, "package.maintainer");
+       char* maintainer = pakfire_archive_get(archive, "package", "maintainer");
        if (maintainer) {
                pakfire_package_set_maintainer(pkg, maintainer);
                free(maintainer);
        }
 
        // Set URL
-       char* url = pakfire_archive_get(archive, "package.url");
+       char* url = pakfire_archive_get(archive, "package", "url");
        if (url) {
                pakfire_package_set_url(pkg, url);
                free(url);
        }
 
        // Set license
-       char* license = pakfire_archive_get(archive, "package.license");
+       char* license = pakfire_archive_get(archive, "package", "license");
        if (license) {
                pakfire_package_set_license(pkg, license);
                free(license);
        }
 
        // Set summary
-       char* summary = pakfire_archive_get(archive, "package.summary");
+       char* summary = pakfire_archive_get(archive, "package", "summary");
        if (summary) {
                pakfire_package_set_summary(pkg, summary);
                free(summary);
        }
 
        // Set description
-       char* description = pakfire_archive_get(archive, "package.description");
+       char* description = pakfire_archive_get(archive, "package", "description");
        if (description) {
                pakfire_package_set_description(pkg, description);
                free(description);
@@ -1341,7 +1341,7 @@ PAKFIRE_EXPORT PakfirePackage pakfire_archive_make_package(PakfireArchive archiv
        pakfire_package_set_downloadsize(pkg, pakfire_archive_get_size(archive));
 
        // Get install size
-       char* size = pakfire_archive_get(archive, "package.size");
+       char* size = pakfire_archive_get(archive, "package", "size");
        if (size) {
                size_t s = pakfire_string_to_size(size);
                free(size);
@@ -1350,21 +1350,21 @@ PAKFIRE_EXPORT PakfirePackage pakfire_archive_make_package(PakfireArchive archiv
        }
 
        // Set vendor
-       char* vendor = pakfire_archive_get(archive, "distribution.vendor");
+       char* vendor = pakfire_archive_get(archive, "distribution", "vendor");
        if (vendor) {
                pakfire_package_set_vendor(pkg, vendor);
                free(vendor);
        }
 
        // Set build host
-       char* build_host = pakfire_archive_get(archive, "build.host");
+       char* build_host = pakfire_archive_get(archive, "build", "host");
        if (build_host) {
                pakfire_package_set_build_host(pkg, build_host);
                free(build_host);
        }
 
        // Set build time
-       char* build_time = pakfire_archive_get(archive, "build.time");
+       char* build_time = pakfire_archive_get(archive, "build", "time");
        if (build_time) {
                time_t t = strtoull(build_time, NULL, 10);
                free(build_time);
@@ -1379,18 +1379,18 @@ PAKFIRE_EXPORT PakfirePackage pakfire_archive_make_package(PakfireArchive archiv
                const char* type;
                void (*func)(PakfirePackage, PakfireRelationList);
        } relations[] = {
-               { "dependencies.provides", pakfire_package_set_provides },
-               { "dependencies.prerequires", pakfire_package_set_prerequires },
-               { "dependencies.requires", pakfire_package_set_requires },
-               { "dependencies.conflicts", pakfire_package_set_conflicts },
-               { "dependencies.obsoletes", pakfire_package_set_obsoletes },
-               { "dependencies.recommends", pakfire_package_set_recommends },
-               { "dependencies.suggests", pakfire_package_set_suggests },
+               { "provides", pakfire_package_set_provides },
+               { "prerequires", pakfire_package_set_prerequires },
+               { "requires", pakfire_package_set_requires },
+               { "conflicts", pakfire_package_set_conflicts },
+               { "obsoletes", pakfire_package_set_obsoletes },
+               { "recommends", pakfire_package_set_recommends },
+               { "suggests", pakfire_package_set_suggests },
                { NULL, NULL },
        };
 
        for (const struct __relation* relation = relations; relation->type; relation++) {
-               char* relations = pakfire_archive_get(archive, relation->type);
+               char* relations = pakfire_archive_get(archive, "dependencies", relation->type);
                if (!relations)
                        continue;
 
index 90e966b82c6666ec1fd864c91f56f5d9db07c996..26da3219b250a28469c998fef729b11b9d2e8522 100644 (file)
@@ -46,7 +46,7 @@ PakfireArchive pakfire_archive_ref(PakfireArchive archive);
 PakfireArchive pakfire_archive_unref(PakfireArchive archive);
 Pakfire pakfire_archive_get_pakfire(PakfireArchive archive);
 
-char* pakfire_archive_get(PakfireArchive archive, const char* key);
+char* pakfire_archive_get(PakfireArchive archive, const char* namespace, const char* key);
 
 PakfireArchive pakfire_archive_open(Pakfire pakfire, const char* path);
 
index 43d763fc96e10fd6a114c6517385c61c7b8a0474..8f2dc3ac8e949f05bb97ab0c213697998e5ad523 100644 (file)
@@ -36,12 +36,12 @@ PakfireParser pakfire_parser_unref(PakfireParser parser);
 PakfireParser pakfire_parser_get_parent(PakfireParser parser);
 
 int pakfire_parser_set(PakfireParser parser,
-               const char* name, const char* value);
+       const char* namespace, const char* name, const char* value);
 int pakfire_parser_append(PakfireParser parser,
-       const char* name, const char* value);
+       const char* namespace, const char* name, const char* value);
 
-char* pakfire_parser_expand(PakfireParser parser, const char* value);
-char* pakfire_parser_get(PakfireParser parser, const char* name);
+char* pakfire_parser_expand(PakfireParser parser, const char* namespace, const char* value);
+char* pakfire_parser_get(PakfireParser parser, const char* namespace, const char* name);
 
 int pakfire_parser_merge(PakfireParser parser1, PakfireParser parser2);
 
@@ -70,6 +70,7 @@ const char* pakfire_parser_error_get_message(struct pakfire_parser_error* error)
 Pakfire pakfire_parser_get_pakfire(PakfireParser parser);
 
 struct pakfire_parser_declaration {
+       char* namespace;
        char* name;
        char* value;
        enum flags {
index ff621c187266e8d73cc39f87c261b29582ecfe13..abf475c50da17d670666bd4351b5b127070233e9 100644 (file)
@@ -43,11 +43,11 @@ struct _PakfireParser {
        size_t num_declarations;
 };
 
-static char* pakfire_parser_make_canonical_name(PakfireParser parser, const char* name) {
+static char* pakfire_parser_make_canonical_name(const char* namespace, const char* name) {
        char* buffer = NULL;
 
-       if (parser->namespace) {
-               int r = asprintf(&buffer, "%s.%s", parser->namespace, name);
+       if (namespace) {
+               int r = asprintf(&buffer, "%s.%s", namespace, name);
                if (r < 0)
                        return NULL;
        } else {
@@ -99,6 +99,8 @@ static void pakfire_parser_free_declarations(PakfireParser parser) {
                struct pakfire_parser_declaration* d = parser->declarations[i];
 
                // Free everything
+               if (d->namespace)
+                       free(d->namespace);
                if (d->name)
                        free(d->name);
                if (d->value)
@@ -143,7 +145,7 @@ PAKFIRE_EXPORT PakfireParser pakfire_parser_get_parent(PakfireParser parser) {
 }
 
 static struct pakfire_parser_declaration* pakfire_parser_get_declaration(
-               PakfireParser parser, const char* name) {
+               PakfireParser parser, const char* namespace, const char* name) {
        struct pakfire_parser_declaration* d;
 
        for (unsigned i = 0; i < parser->num_declarations; i++) {
@@ -151,6 +153,14 @@ static struct pakfire_parser_declaration* pakfire_parser_get_declaration(
                if (!d)
                        break;
 
+               // Skip if d does not have a namespace set
+               if (namespace && !d->namespace)
+                       continue;
+
+               // Skip if namespace does not match
+               if (namespace && strcmp(d->namespace, namespace) != 0)
+                       continue;
+
                // Compare the name
                if (strcmp(d->name, name) == 0)
                        return d;
@@ -159,13 +169,13 @@ static struct pakfire_parser_declaration* pakfire_parser_get_declaration(
        return NULL;
 }
 
-static int pakfire_parser_set_declaration(PakfireParser parser,
-               const char* name, const char* value) {
+PAKFIRE_EXPORT int pakfire_parser_set(PakfireParser parser,
+               const char* namespace, const char* name, const char* value) {
        if (!name)
                return -EINVAL;
 
        // Handle when name already exists
-       struct pakfire_parser_declaration* d = pakfire_parser_get_declaration(parser, name);
+       struct pakfire_parser_declaration* d = pakfire_parser_get_declaration(parser, namespace, name);
        if (d) {
                // Replace value
                if (d->value)
@@ -176,8 +186,8 @@ static int pakfire_parser_set_declaration(PakfireParser parser,
                else
                        d->value = NULL;
 
-               DEBUG(parser->pakfire, "%p: Updated declaration: %s = %s\n",
-                       parser, d->name, d->value);
+               DEBUG(parser->pakfire, "%p: Updated declaration: %s.%s = %s\n",
+                       parser, d->namespace, d->name, d->value);
 
                // All done
                return 0;
@@ -188,12 +198,19 @@ static int pakfire_parser_set_declaration(PakfireParser parser,
        if (!d)
                return -1;
 
+       // Copy namespace
+       if (namespace)
+               d->namespace = strdup(namespace);
+       else
+               d->namespace = NULL;
+
        // Import name & value
        d->name = strdup(name);
        if (value)
                d->value = strdup(value);
 
-       DEBUG(parser->pakfire, "%p: New declaration: %s = %s\n", parser, d->name, d->value);
+       DEBUG(parser->pakfire, "%p: New declaration: %s.%s = %s\n",
+               parser, d->namespace, d->name, d->value);
 
        // Assign new declaration to array
        parser->declarations = reallocarray(parser->declarations,
@@ -203,20 +220,16 @@ static int pakfire_parser_set_declaration(PakfireParser parser,
        return 0;
 }
 
-PAKFIRE_EXPORT int pakfire_parser_set(PakfireParser parser, const char* name, const char* value) {
-       return pakfire_parser_set_declaration(parser, name, value);
-}
-
 int pakfire_parser_apply_declaration(PakfireParser parser,
                struct pakfire_parser_declaration* declaration) {
        if (declaration->flags & PAKFIRE_PARSER_DECLARATION_APPEND)
-               return pakfire_parser_append(parser, declaration->name, declaration->value);
+               return pakfire_parser_append(parser, declaration->namespace, declaration->name, declaration->value);
 
-       return pakfire_parser_set(parser, declaration->name, declaration->value);
+       return pakfire_parser_set(parser, declaration->namespace, declaration->name, declaration->value);
 }
 
-static const char* pakfire_parser_get_raw(PakfireParser parser, const char* name) {
-       struct pakfire_parser_declaration* d = pakfire_parser_get_declaration(parser, name);
+static const char* pakfire_parser_get_raw(PakfireParser parser, const char* namespace, const char* name) {
+       struct pakfire_parser_declaration* d = pakfire_parser_get_declaration(parser, namespace, name);
 
        // Return a match when it actually contains a string
        if (d) {
@@ -228,21 +241,21 @@ static const char* pakfire_parser_get_raw(PakfireParser parser, const char* name
 
        // Search in parent parser if available
        if (parser->parent)
-               return pakfire_parser_get_raw(parser->parent, name);
+               return pakfire_parser_get_raw(parser->parent, namespace, name);
 
        return NULL;
 }
 
 PAKFIRE_EXPORT int pakfire_parser_append(PakfireParser parser,
-               const char* name, const char* value) {
+               const char* namespace, const char* name, const char* value) {
        char* buffer = NULL;
 
        // Fetch the value of the current declaration
-       const char* old_value = pakfire_parser_get_raw(parser, name);
+       const char* old_value = pakfire_parser_get_raw(parser, namespace, name);
 
        // Set the new value when there is no old one
        if (!old_value)
-               return pakfire_parser_set_declaration(parser, name, value);
+               return pakfire_parser_set(parser, namespace, name, value);
 
        // Concat value
        int r = asprintf(&buffer, "%s %s", old_value, value);
@@ -250,72 +263,59 @@ PAKFIRE_EXPORT int pakfire_parser_append(PakfireParser parser,
                return r;
 
        // Set the new value
-       r = pakfire_parser_set_declaration(parser, name, buffer);
+       r = pakfire_parser_set(parser, namespace, name, buffer);
        free(buffer);
 
        return r;
 }
 
-static void pakfire_parser_strip_namespace(char* s) {
-       char* pos = strrchr(s, '.');
+static void pakfire_parser_strip_namespace(char** s) {
+       char* pos = strrchr(*s, '.');
 
        if (pos)
-               s[pos - s] = '\0';
+               *s[pos - *s] = '\0';
        else
-               s[0] = '\0';
+               *s = NULL;
 }
 
 static struct pakfire_parser_declaration* pakfire_parser_find_declaration(
-               PakfireParser parser, const char* name) {
+               PakfireParser parser, const char* namespace, const char* name) {
        char* n = NULL;
 
-       // Create a working copy of the namespace
-       if (parser->namespace)
-               n = strdup(parser->namespace);
-
-       size_t length = ((n) ? strlen(n) : 0) + strlen(name) + 1;
-       char* buffer = malloc(length + 1);
+       // Create a working copy of the namespace variable
+       if (namespace)
+               n = strdupa(namespace);
 
        struct pakfire_parser_declaration* d = NULL;
-
        while (1) {
-               if (n && *n)
-                       snprintf(buffer, length + 1, "%s.%s", n, name);
-               else
-                       snprintf(buffer, length + 1, "%s", name);
-
-               DEBUG(parser->pakfire, "Looking up %s in parser %p\n", buffer, parser);
+               DEBUG(parser->pakfire, "Looking up %s.%s in parser %p\n", n, name, parser);
 
                // Lookup declaration
-               d = pakfire_parser_get_declaration(parser, buffer);
+               d = pakfire_parser_get_declaration(parser, n, name);
 
                // End if we have found a match
                if (d)
                        break;
 
                // End if namespace is empty
-               if (!n || !*n)
+               if (!n)
                        break;
 
                /*
                        If we did not find a match, we will remove one level of the
                        namespace and try again...
                */
-               pakfire_parser_strip_namespace(n);
+               pakfire_parser_strip_namespace(&n);
        }
 
-       free(buffer);
-
-       if (n)
-               free(n);
-
        if (!d && parser->parent)
-               d = pakfire_parser_find_declaration(parser->parent, name);
+               d = pakfire_parser_find_declaration(parser->parent, namespace, name);
 
        return d;
 }
 
-PAKFIRE_EXPORT char* pakfire_parser_expand(PakfireParser parser, const char* value) {
+PAKFIRE_EXPORT char* pakfire_parser_expand(PakfireParser parser,
+               const char* namespace, const char* value) {
        // Return NULL when the value is NULL
        if (!value)
                return NULL;
@@ -365,7 +365,7 @@ PAKFIRE_EXPORT char* pakfire_parser_expand(PakfireParser parser, const char* val
 
                // Search for a declaration of this variable
                struct pakfire_parser_declaration* v =
-                       pakfire_parser_find_declaration(parser, variable);
+                       pakfire_parser_find_declaration(parser, namespace, variable);
 
                const char* value = NULL;
                if (v && v->value) {
@@ -409,15 +409,15 @@ PAKFIRE_EXPORT char* pakfire_parser_expand(PakfireParser parser, const char* val
        return buffer;
 }
 
-PAKFIRE_EXPORT char* pakfire_parser_get(PakfireParser parser, const char* name) {
-       const char* value = pakfire_parser_get_raw(parser, name);
+PAKFIRE_EXPORT char* pakfire_parser_get(PakfireParser parser, const char* namespace, const char* name) {
+       const char* value = pakfire_parser_get_raw(parser, namespace, name);
 
        // Return NULL when nothing was found
        if (!value)
                return NULL;
 
        // Otherwise return the expanded value
-       return pakfire_parser_expand(parser, value);
+       return pakfire_parser_expand(parser, namespace, value);
 }
 
 PAKFIRE_EXPORT int pakfire_parser_merge(PakfireParser parser1, PakfireParser parser2) {
@@ -427,16 +427,26 @@ PAKFIRE_EXPORT int pakfire_parser_merge(PakfireParser parser1, PakfireParser par
        if (parser1 == parser2)
                return EINVAL;
 
+       char* namespace = NULL;
+
        for (unsigned int i = 0; i < parser2->num_declarations; i++) {
                struct pakfire_parser_declaration* d = parser2->declarations[i];
                if (!d)
                        break;
 
-               char* canonical_name = pakfire_parser_make_canonical_name(parser2, d->name);
+               if (parser2->namespace && d->namespace)
+                       asprintf(&namespace, "%s.%s", parser2->namespace, d->namespace);
+               else if (parser2->namespace)
+                       asprintf(&namespace, "%s", parser2->namespace);
+               else if (d->namespace)
+                       asprintf(&namespace, "%s", d->namespace);
+               else
+                       namespace = NULL;
 
-               int r = pakfire_parser_set_declaration(parser1, canonical_name, d->value);
+               int r = pakfire_parser_set(parser1, namespace, d->name, d->value);
 
-               free(canonical_name);
+               if (namespace)
+                       free(namespace);
 
                if (r)
                        return r;
@@ -482,14 +492,18 @@ PAKFIRE_EXPORT int pakfire_parser_parse(PakfireParser parser,
 PAKFIRE_EXPORT char* pakfire_parser_dump(PakfireParser parser) {
        char* s = NULL;
 
+       char buffer[1024];
+
        for (unsigned int i = 0; i < parser->num_declarations; i++) {
                struct pakfire_parser_declaration* d = parser->declarations[i];
 
                if (d) {
-                       if (s)
-                               asprintf(&s, "%s%-24s = %s\n", s, d->name, d->value);
+                       if (d->namespace)
+                               snprintf(buffer, sizeof(buffer) - 1, "%s.%s", d->namespace, d->name);
                        else
-                               asprintf(&s, "%-24s = %s\n", d->name, d->value);
+                               snprintf(buffer, sizeof(buffer) - 1, "%s", d->name);
+
+                       asprintf(&s, "%s%-24s = %s\n", (s) ? s : "", buffer, d->value);
                }
        }
 
index 182574301c004e14ed7500dec228205cb029bfc4..47432bd1ac4f791a622911a3bc9454eee4bb81cf 100644 (file)
@@ -84,6 +84,9 @@ static inline int pakfire_parser_new_declaration(
        if (!d)
                return ENOMEM;
 
+       // Set namespace
+       d->namespace = NULL;
+
        // Copy name
        d->name = strdup(name);
 
@@ -298,7 +301,7 @@ subparser                                   : subparser_name T_EOL subgrammar T_END T_EOL
                                                                if (r)
                                                                        ABORT;
 
-                                                               pakfire_parser_set($$, key, value);
+                                                               pakfire_parser_set($$, NULL, key, value);
 
                                                                if (key)
                                                                        free(key);
@@ -400,8 +403,8 @@ static PakfireParser make_if_stmt(Pakfire pakfire, PakfireParser* parser, const
        DEBUG(pakfire, "  parser = %p, if = %p, else = %p\n", *parser, if_block, else_block);
 
        // Expand values
-       char* v1 = pakfire_parser_expand(*parser, val1);
-       char* v2 = pakfire_parser_expand(*parser, val2);
+       char* v1 = pakfire_parser_expand(*parser, NULL, val1);
+       char* v2 = pakfire_parser_expand(*parser, NULL, val2);
 
        PakfireParser result = NULL;
 
index e4583b0837153abb96230ee5da9652a6a849e126..f5a79533ebe48aa3abeae44a719f0678a14787ea 100644 (file)
@@ -333,7 +333,7 @@ class BuilderContext(object):
                # Parse all metadata
                package = archive.get_package()
 
-               requires = archive.get("dependencies.requires")
+               requires = archive.get("dependencies", "requires")
                if requires:
                        packages += requires.splitlines()
 
index efe7e0ecac0d3cdafa285b3f885ac2d98e3386ad..bd3c5d01ca19660ec2895ba53f8c35aa1c0ac90c 100644 (file)
@@ -33,23 +33,23 @@ static int test_parser(const struct test* t) {
        PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL);
 
        // Retrieve a value that does not exist
-       value = pakfire_parser_get(parser, "null");
+       value = pakfire_parser_get(parser, NULL, "null");
        ASSERT(!value);
 
        // Set a value
-       int r = pakfire_parser_set(parser, "a", "a");
+       int r = pakfire_parser_set(parser, NULL, "a", "a");
        ASSERT(r == 0);
 
        // Retrieve the value again
-       value = pakfire_parser_get(parser, "a");
+       value = pakfire_parser_get(parser, NULL, "a");
        ASSERT_STRING_EQUALS(value, "a");
 
        // Append something to the value
-       r = pakfire_parser_append(parser, "a", "b");
+       r = pakfire_parser_append(parser, NULL, "a", "b");
        ASSERT(r == 0);
 
        // Retrieve the value again
-       value = pakfire_parser_get(parser, "a");
+       value = pakfire_parser_get(parser, NULL, "a");
        ASSERT_STRING_EQUALS(value, "a b");
 
        // Make a child parser
@@ -57,39 +57,35 @@ static int test_parser(const struct test* t) {
        ASSERT(subparser);
 
        // Try to get a again
-       value = pakfire_parser_get(subparser, "a");
+       value = pakfire_parser_get(subparser, NULL, "a");
        ASSERT_STRING_EQUALS(value, "a b");
 
        // Append something to the subparser
-       r = pakfire_parser_append(subparser, "a", "c");
+       r = pakfire_parser_append(subparser, NULL, "a", "c");
        ASSERT(r == 0);
 
        // The subparser should return "a b c"
-       value = pakfire_parser_get(subparser, "a");
+       value = pakfire_parser_get(subparser, NULL, "a");
        ASSERT_STRING_EQUALS(value, "a b c");
 
        // The original parser should remain unchanged
-       value = pakfire_parser_get(parser, "a");
+       value = pakfire_parser_get(parser, NULL, "a");
        ASSERT_STRING_EQUALS(value, "a b");
 
        // Set another value
-       r = pakfire_parser_append(subparser, "b", "1");
+       r = pakfire_parser_append(subparser, NULL, "b", "1");
        ASSERT(r == 0);
 
        // Merge the two parsers
        pakfire_parser_merge(parser, subparser);
 
-       // Now a should have changed to "a b c"
-       value = pakfire_parser_get(parser, "child.a");
-       ASSERT_STRING_EQUALS(value, "a b c");
-
        // Set a variable
-       r = pakfire_parser_set(parser, "c", "%{b}");
+       r = pakfire_parser_set(parser, NULL, "c", "%{b}");
        ASSERT(r == 0);
 
        // Get the value of c
-       value = pakfire_parser_get(parser, "c");
-       ASSERT_STRING_EQUALS(value, "");
+       value = pakfire_parser_get(parser, NULL, "c");
+       ASSERT_STRING_EQUALS(value, "1");
 
        // Dump the parser
        char* s = pakfire_parser_dump(parser);