From: Michael Tremer Date: Wed, 2 Jun 2021 15:57:21 +0000 (+0000) Subject: parser: Carry over flags when merging parsers X-Git-Tag: 0.9.28~1285^2~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fea2e884e663704c64725bfe4607d9b4e8f29cf4;p=pakfire.git parser: Carry over flags when merging parsers Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/parser.c b/src/_pakfire/parser.c index 1e7df2955..e391f8e28 100644 --- a/src/_pakfire/parser.c +++ b/src/_pakfire/parser.c @@ -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; diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index c837d7856..4ea9f985a 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -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++) { diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index 1dbd37590..3cd2b6a1a 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -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; diff --git a/src/libpakfire/include/pakfire/parser.h b/src/libpakfire/include/pakfire/parser.h index d572a1f87..b0acd3051 100644 --- a/src/libpakfire/include/pakfire/parser.h +++ b/src/libpakfire/include/pakfire/parser.h @@ -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); diff --git a/src/libpakfire/parser.c b/src/libpakfire/parser.c index 74c93a45e..0b105e79c 100644 --- a/src/libpakfire/parser.c +++ b/src/libpakfire/parser.c @@ -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; } diff --git a/src/libpakfire/parser/grammar.y b/src/libpakfire/parser/grammar.y index 07486fa5b..0a392d9b4 100644 --- a/src/libpakfire/parser/grammar.y +++ b/src/libpakfire/parser/grammar.y @@ -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) diff --git a/tests/libpakfire/makefile.c b/tests/libpakfire/makefile.c index 5d3216432..e3bc9d771 100644 --- a/tests/libpakfire/makefile.c +++ b/tests/libpakfire/makefile.c @@ -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); diff --git a/tests/libpakfire/parser.c b/tests/libpakfire/parser.c index 383e9db40..846bca8c7 100644 --- a/tests/libpakfire/parser.c +++ b/tests/libpakfire/parser.c @@ -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");