]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
parser: Carry over flags when merging parsers
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Jun 2021 15:57:21 +0000 (15:57 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 2 Jun 2021 15:57:21 +0000 (15:57 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/parser.c
src/libpakfire/build.c
src/libpakfire/dist.c
src/libpakfire/include/pakfire/parser.h
src/libpakfire/parser.c
src/libpakfire/parser/grammar.y
tests/libpakfire/makefile.c
tests/libpakfire/parser.c

index 1e7df295560fb02c02c9ec8a6e96473763ffc0a1..e391f8e28030cc17a17929f59b010ed80c2b3b00 100644 (file)
@@ -154,7 +154,7 @@ static PyObject* Parser_set(ParserObject* self, PyObject* args) {
        if (!PyArg_ParseTuple(args, "zsz", &namespace, &key, &value))
                return NULL;
 
-       int r = pakfire_parser_set(self->parser, namespace, key, value);
+       int r = pakfire_parser_set(self->parser, namespace, key, value, 0);
        if (r) {
                PyErr_SetFromErrno(PyExc_OSError);
                return NULL;
index c837d7856cf8e203ec2f8c14d7fcb6d9df491698..4ea9f985a731e181fb75e0385bc61543fc079176 100644 (file)
@@ -530,7 +530,7 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path,
        }
 
        // Set BUILDROOT
-       pakfire_parser_set(makefile, NULL, "BUILDROOT", buildroot_rel);
+       pakfire_parser_set(makefile, NULL, "BUILDROOT", buildroot_rel, 0);
 
        // Run through all build stages
        for (const char** stage = stages; *stage; stage++) {
index 1dbd3759085918e97134ad78d9efbec6ad0b9e64..3cd2b6a1a5b0028ea49d7b2271e5992a829dcefa 100644 (file)
@@ -50,57 +50,57 @@ static int pakfire_makefile_set_defaults(Pakfire pakfire,
        int r;
 
        // Set epoch
-       pakfire_parser_set(parser, NULL, "epoch", "0");
+       pakfire_parser_set(parser, NULL, "epoch", "0", 0);
 
        // Set vendor
-       pakfire_parser_set(parser, NULL, "vendor", "%{DISTRO_VENDOR}");
+       pakfire_parser_set(parser, NULL, "vendor", "%{DISTRO_VENDOR}", 0);
 
        // Set DISTRO_NAME
        const char* name = pakfire_get_distro_name(pakfire);
        if (name)
-               pakfire_parser_set(parser, NULL, "DISTRO_NAME", name);
+               pakfire_parser_set(parser, NULL, "DISTRO_NAME", name, 0);
 
        // Set DISTRO_SNAME
        const char* id = pakfire_get_distro_id(pakfire);
        if (id)
-               pakfire_parser_set(parser, NULL, "DISTRO_SNAME", name);
+               pakfire_parser_set(parser, NULL, "DISTRO_SNAME", name, 0);
 
        // Set DISTRO_RELEASE
        const char* version_id = pakfire_get_distro_version_id(pakfire);
        if (version_id)
-               pakfire_parser_set(parser, NULL, "DISTRO_RELEASE", version_id);
+               pakfire_parser_set(parser, NULL, "DISTRO_RELEASE", version_id, 0);
 
        // Set DISTRO_DISTTAG
        if (id && version_id) {
                pakfire_string_format(buffer, "%s%s", id, version_id);
 
-               pakfire_parser_set(parser, NULL, "DISTRO_DISTTAG", buffer);
+               pakfire_parser_set(parser, NULL, "DISTRO_DISTTAG", buffer, 0);
        }
 
        // Set DISTRO_VENDOR
        const char* vendor = pakfire_get_distro_vendor(pakfire);
        if (vendor)
-               pakfire_parser_set(parser, NULL, "DISTRO_VENDOR", vendor);
+               pakfire_parser_set(parser, NULL, "DISTRO_VENDOR", vendor, 0);
 
        // Set DISTRO_ARCH
        const char* arch = pakfire_get_arch(pakfire);
        if (arch) {
-               pakfire_parser_set(parser, NULL, "DISTRO_ARCH", arch);
+               pakfire_parser_set(parser, NULL, "DISTRO_ARCH", arch, 0);
 
                const char* platform = pakfire_arch_platform(arch);
                if (platform)
-                       pakfire_parser_set(parser, NULL, "DISTRO_PLATFORM", platform);
+                       pakfire_parser_set(parser, NULL, "DISTRO_PLATFORM", platform, 0);
 
                if (vendor) {
                        // Set DISTRO_MACHINE
                        r = pakfire_arch_machine(buffer, arch, vendor);
                        if (!r)
-                               pakfire_parser_set(parser, NULL, "DISTRO_MACHINE", buffer);
+                               pakfire_parser_set(parser, NULL, "DISTRO_MACHINE", buffer, 0);
 
                        // Set DISTRO_BUILDTARGET
                        r = pakfire_arch_buildtarget(buffer, arch, vendor);
                        if (!r)
-                               pakfire_parser_set(parser, NULL, "DISTRO_BUILDTARGET", buffer);
+                               pakfire_parser_set(parser, NULL, "DISTRO_BUILDTARGET", buffer, 0);
                }
        }
 
@@ -109,7 +109,8 @@ static int pakfire_makefile_set_defaults(Pakfire pakfire,
        if (dirname) {
                const char* root = pakfire_get_path(pakfire);
 
-               pakfire_parser_set(parser, NULL, "BASEDIR", pakfire_path_relpath(root, dirname));
+               pakfire_parser_set(parser, NULL, "BASEDIR",
+                       pakfire_path_relpath(root, dirname), 0);
                free(dirname);
        }
 
@@ -375,7 +376,7 @@ PAKFIRE_EXPORT int pakfire_dist(Pakfire pakfire, const char* path, const char* t
        }
 
        // The architecture is always "src"
-       r = pakfire_parser_set(makefile, NULL, "arch", "src");
+       r = pakfire_parser_set(makefile, NULL, "arch", "src", 0);
        if (r)
                goto ERROR;
 
index d572a1f879ff0d72a134b6cbf548e1dd18e1f587..b0acd305130eaf47293c47ffc48ae5cad9f2c986 100644 (file)
@@ -41,7 +41,7 @@ PakfireParser pakfire_parser_unref(PakfireParser parser);
 PakfireParser pakfire_parser_get_parent(PakfireParser parser);
 
 int pakfire_parser_set(PakfireParser parser,
-       const char* namespace, const char* name, const char* value);
+       const char* namespace, const char* name, const char* value, int flags);
 int pakfire_parser_append(PakfireParser parser,
        const char* namespace, const char* name, const char* value);
 
index 74c93a45e9aef64940a6e6ec2b27a3c0f7982b79..0b105e79cb75e0b67eaf5deffcc36e93d5710f86 100644 (file)
@@ -271,7 +271,7 @@ static struct pakfire_parser_declaration* pakfire_parser_find_declaration(
 }
 
 PAKFIRE_EXPORT int pakfire_parser_set(PakfireParser parser,
-               const char* namespace, const char* name, const char* value) {
+               const char* namespace, const char* name, const char* value, int flags) {
        if (!name)
                return -EINVAL;
 
@@ -290,6 +290,10 @@ PAKFIRE_EXPORT int pakfire_parser_set(PakfireParser parser,
                else
                        d->value = NULL;
 
+               // Update flags
+               if (flags)
+                       d->flags = flags;
+
                DEBUG(parser->pakfire, "%p: Updated declaration: %s.%s = %s\n",
                        parser, d->namespace, d->name, d->value);
 
@@ -310,6 +314,9 @@ PAKFIRE_EXPORT int pakfire_parser_set(PakfireParser parser,
        if (value)
                d->value = strdup(value);
 
+       // Import flags
+       d->flags = flags;
+
        DEBUG(parser->pakfire, "%p: New declaration: %s.%s = %s\n",
                parser, d->namespace, d->name, d->value);
 
@@ -326,7 +333,8 @@ int pakfire_parser_apply_declaration(PakfireParser parser,
        if (declaration->flags & PAKFIRE_PARSER_DECLARATION_APPEND)
                return pakfire_parser_append(parser, declaration->namespace, declaration->name, declaration->value);
 
-       return pakfire_parser_set(parser, declaration->namespace, declaration->name, declaration->value);
+       return pakfire_parser_set(parser, declaration->namespace,
+               declaration->name, declaration->value, declaration->flags);
 }
 
 static const char* pakfire_parser_find_template(PakfireParser parser,
@@ -387,7 +395,7 @@ PAKFIRE_EXPORT int pakfire_parser_append(PakfireParser parser,
 
        // Set the new value when there is no old one
        if (!old_value)
-               return pakfire_parser_set(parser, namespace, name, value);
+               return pakfire_parser_set(parser, namespace, name, value, 0);
 
        // Concat value
        int r = asprintf(&buffer, "%s %s", old_value, value);
@@ -395,7 +403,7 @@ PAKFIRE_EXPORT int pakfire_parser_append(PakfireParser parser,
                return r;
 
        // Set the new value
-       r = pakfire_parser_set(parser, namespace, name, buffer);
+       r = pakfire_parser_set(parser, namespace, name, buffer, 0);
        free(buffer);
 
        return r;
@@ -734,7 +742,7 @@ PAKFIRE_EXPORT int pakfire_parser_merge(PakfireParser parser1, PakfireParser par
                else
                        pakfire_string_set(namespace, "");
 
-               int r = pakfire_parser_set(parser1, namespace, d->name, d->value);
+               int r = pakfire_parser_set(parser1, namespace, d->name, d->value, d->flags);
                if (r)
                        return r;
        }
index 07486fa5b3144e96d2d9089078a684e14dec8cdb..0a392d9b41e5a304cd8cb5ce6f7557d4b91e564e 100644 (file)
@@ -313,7 +313,7 @@ subparser                                   : subparser_name T_EOL block T_END T_EOL
                                                                int r = pakfire_string_partition($1, ":", &key, &value);
                                                                if (r == 0) {
                                                                        if (strcmp("package", key) == 0) {
-                                                                               pakfire_parser_set($$, NULL, "name", value);
+                                                                               pakfire_parser_set($$, NULL, "name", value, 0);
                                                                        }
 
                                                                        if (key)
@@ -341,11 +341,11 @@ subparser                                 : subparser_name T_EOL block T_END T_EOL
                                                                        pakfire_parser_set_namespace($$, $1);
 
                                                                        // Set the name (because we cannot have empty parsers)
-                                                                       pakfire_parser_set($$, NULL, "name", value);
+                                                                       pakfire_parser_set($$, NULL, "name", value, 0);
 
                                                                // Handle all other cases
                                                                } else {
-                                                                       pakfire_parser_set($$, NULL, key, value);
+                                                                       pakfire_parser_set($$, NULL, key, value, 0);
                                                                }
 
                                                                if (key)
index 5d32164327baac94d186d1a3302c67bd94351d10..e3bc9d7712da4b446e50d7b8801be6456d915450 100644 (file)
@@ -103,7 +103,7 @@ static int test_packages(const struct test* t) {
        ASSERT(parser);
 
        // Set some architecture
-       pakfire_parser_set(parser, NULL, "DISTRO_ARCH", "x86_64");
+       pakfire_parser_set(parser, NULL, "DISTRO_ARCH", "x86_64", 0);
 
        // Load macros
        int r = load_macros(parser);
index 383e9db40c8c38c1c37de2ef593cd6bc38fc2ce2..846bca8c79e4d0624d603850e5ffcb6cf6d523c1 100644 (file)
@@ -38,7 +38,7 @@ static int test_parser(const struct test* t) {
        ASSERT(!value);
 
        // Set a value
-       int r = pakfire_parser_set(parser, NULL, "a", "a");
+       int r = pakfire_parser_set(parser, NULL, "a", "a", 0);
        ASSERT(r == 0);
 
        // Retrieve the value again
@@ -81,7 +81,7 @@ static int test_parser(const struct test* t) {
        pakfire_parser_merge(parser, subparser);
 
        // Set a variable
-       r = pakfire_parser_set(parser, NULL, "c", "%{b}");
+       r = pakfire_parser_set(parser, NULL, "c", "%{b}", 0);
        ASSERT(r == 0);
 
        // Get the value of c
@@ -148,7 +148,7 @@ static int test_parser_command(const struct test* t) {
                PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS);
        ASSERT(parser);
 
-       ASSERT(pakfire_parser_set(parser, NULL, "command", command) == 0);
+       ASSERT(pakfire_parser_set(parser, NULL, "command", command, 0) == 0);
 
        // Retrieve the expanded value
        char* value = pakfire_parser_get(parser, NULL, "command");