From d9cb3ba71c0dc12e623ab468632750c2c1943529 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Tue, 26 Jul 2022 19:35:17 -0400 Subject: [PATCH] Add support for stream overrides in configurations Fixes: https://github.com/fedora-modularity/libmodulemd/issues/599 Signed-off-by: Stephen Gallagher --- .../modulemd-2.0/modulemd-build-config.h | 29 ++++++++++++ modulemd/modulemd-build-config.c | 44 +++++++++++++++++++ modulemd/modulemd-packager-v3.c | 7 +++ modulemd/tests/test-modulemd-packager-v3.c | 6 ++- .../upgrades/packager_v3_to_index.yaml | 2 +- .../upgrades/packager_v3_to_stream_v2.yaml | 2 +- yaml_specs/modulemd_packager_v3.yaml | 6 ++- 7 files changed, 92 insertions(+), 4 deletions(-) diff --git a/modulemd/include/modulemd-2.0/modulemd-build-config.h b/modulemd/include/modulemd-2.0/modulemd-build-config.h index 798f5b698..5546d82a1 100644 --- a/modulemd/include/modulemd-2.0/modulemd-build-config.h +++ b/modulemd/include/modulemd-2.0/modulemd-build-config.h @@ -110,6 +110,35 @@ const gchar * modulemd_build_config_get_platform (ModulemdBuildConfig *self); +/** + * modulemd_build_config_set_stream: + * @self: This #ModulemdBuildConfig object. + * @stream: A stream name to use as an override for this configuration. + * + * Set the stream name override for this build configuration. + * + * Since: 2.15 + */ +void +modulemd_build_config_set_stream (ModulemdBuildConfig *self, + const gchar *stream); + + +/** + * modulemd_build_config_get_stream: + * @self: This #ModulemdBuildConfig object. + * + * Get the stream override for this build configuration. + * + * Returns: (transfer none): The string representing the overridden stream + * name. + * + * Since name: 2.15 + */ +const gchar * +modulemd_build_config_get_stream (ModulemdBuildConfig *self); + + /** * modulemd_build_config_add_runtime_requirement: * @self: (in): This #ModulemdBuildConfig object. diff --git a/modulemd/modulemd-build-config.c b/modulemd/modulemd-build-config.c index 80b62f0a4..ed78d4bf7 100644 --- a/modulemd/modulemd-build-config.c +++ b/modulemd/modulemd-build-config.c @@ -26,6 +26,7 @@ struct _ModulemdBuildConfig gchar *context; gchar *platform; + gchar *stream; GHashTable *requires; /* hashtable */ GHashTable *buildrequires; /* hashtable */ ModulemdBuildopts *buildopts; @@ -46,6 +47,7 @@ modulemd_build_config_finalize (GObject *object) g_clear_pointer (&self->context, g_free); g_clear_pointer (&self->platform, g_free); + g_clear_pointer (&self->stream, g_free); g_clear_pointer (&self->requires, g_hash_table_unref); g_clear_pointer (&self->buildrequires, g_hash_table_unref); g_clear_object (&self->buildopts); @@ -119,6 +121,30 @@ modulemd_build_config_get_platform (ModulemdBuildConfig *self) } +void +modulemd_build_config_set_stream (ModulemdBuildConfig *self, + const gchar *stream) +{ + g_return_if_fail (MODULEMD_IS_BUILD_CONFIG (self)); + + g_clear_pointer (&self->stream, g_free); + + if (stream) + { + self->stream = g_strdup (stream); + } +} + + +const gchar * +modulemd_build_config_get_stream (ModulemdBuildConfig *self) +{ + g_return_val_if_fail (MODULEMD_IS_BUILD_CONFIG (self), NULL); + + return self->stream; +} + + void modulemd_build_config_add_runtime_requirement (ModulemdBuildConfig *self, const gchar *module_name, @@ -340,6 +366,10 @@ modulemd_build_config_parse_yaml (yaml_parser_t *parser, MMD_SET_PARSED_YAML_STRING ( parser, error, modulemd_build_config_set_platform, buildconfig); + else if (g_str_equal (event.data.scalar.value, "stream")) + MMD_SET_PARSED_YAML_STRING ( + parser, error, modulemd_build_config_set_stream, buildconfig); + else if (g_str_equal ((const gchar *)event.data.scalar.value, "buildrequires")) { @@ -443,6 +473,11 @@ modulemd_build_config_emit_yaml (ModulemdBuildConfig *self, EMIT_KEY_VALUE_IF_SET (emitter, error, "context", self->context); EMIT_KEY_VALUE_IF_SET (emitter, error, "platform", self->platform); + if (self->stream) + { + EMIT_KEY_VALUE_FULL (emitter, error, "stream", self->stream, YAML_DOUBLE_QUOTED_SCALAR_STYLE); + } + if (!modulemd_build_config_emit_deptable ( self->buildrequires, "buildrequires", emitter, error)) { @@ -658,6 +693,9 @@ modulemd_build_config_copy (ModulemdBuildConfig *self) modulemd_build_config_set_platform ( copy, modulemd_build_config_get_platform (self)); + modulemd_build_config_set_stream (copy, + modulemd_build_config_get_stream (self)); + if (self->requires) { modulemd_build_config_replace_runtime_deps (copy, self->requires); @@ -763,6 +801,12 @@ modulemd_build_config_compare (ModulemdBuildConfig *self_1, return cmp; } + cmp = g_strcmp0 (self_1->stream, self_2->stream); + if (cmp != 0) + { + return cmp; + } + cmp = modulemd_hash_table_compare ( self_1->buildrequires, self_2->buildrequires, modulemd_strcmp_wrapper); if (cmp != 0) diff --git a/modulemd/modulemd-packager-v3.c b/modulemd/modulemd-packager-v3.c index 7e77d058f..c2052d379 100644 --- a/modulemd/modulemd-packager-v3.c +++ b/modulemd/modulemd-packager-v3.c @@ -950,6 +950,13 @@ copy_packager_v3_buildconfig_to_stream_v2 (ModulemdModuleStreamV2 *stream_v2, { g_autoptr (ModulemdDependencies) deps = NULL; g_auto (GStrv) modules = NULL; + const gchar *stream_override = NULL; + + stream_override = modulemd_build_config_get_stream (bc); + if (stream_override) + { + modulemd_module_stream_set_stream_name (MODULEMD_MODULE_STREAM (stream_v2), stream_override); + } modulemd_module_stream_v2_set_buildopts ( stream_v2, modulemd_build_config_get_buildopts (bc)); diff --git a/modulemd/tests/test-modulemd-packager-v3.c b/modulemd/tests/test-modulemd-packager-v3.c index 581a7e310..61f0bbc02 100644 --- a/modulemd/tests/test-modulemd-packager-v3.c +++ b/modulemd/tests/test-modulemd-packager-v3.c @@ -347,6 +347,7 @@ validate_yaml (ModulemdPackagerV3 *packager) " arches: [i686, x86_64]\n" " - context: CTX2\n" " platform: f33\n" + " stream: \"older\"\n" " references:\n" " community: http://www.example.com/\n" " documentation: http://www.example.com/\n" @@ -508,7 +509,7 @@ packager_test_convert_to_index_with_name_stream_default_profile (void) g_assert_no_error (error); g_assert_nonnull (yaml_str); - g_debug ("YAML dump of index from PackageV3 to Index mapping:\n%s", + g_debug ("YAML dump of index from PackagerV3 to Index mapping:\n%s", yaml_str); expected_path = g_strdup_printf ("%s/upgrades/packager_v3_to_index.yaml", @@ -519,6 +520,9 @@ packager_test_convert_to_index_with_name_stream_default_profile (void) g_assert_no_error (error); g_assert_nonnull (expected_str); + g_debug ("YAML dump of the expected string:\n%s", + expected_str); + g_assert_cmpstr (expected_str, ==, yaml_str); g_clear_object (&index); diff --git a/modulemd/tests/test_data/upgrades/packager_v3_to_index.yaml b/modulemd/tests/test_data/upgrades/packager_v3_to_index.yaml index 1e369200d..f9646f727 100644 --- a/modulemd/tests/test_data/upgrades/packager_v3_to_index.yaml +++ b/modulemd/tests/test_data/upgrades/packager_v3_to_index.yaml @@ -102,7 +102,7 @@ document: modulemd version: 2 data: name: foo - stream: "latest" + stream: "older" context: CTX2 summary: An example module description: >- diff --git a/modulemd/tests/test_data/upgrades/packager_v3_to_stream_v2.yaml b/modulemd/tests/test_data/upgrades/packager_v3_to_stream_v2.yaml index 345b5ef3f..118c29b9e 100644 --- a/modulemd/tests/test_data/upgrades/packager_v3_to_stream_v2.yaml +++ b/modulemd/tests/test_data/upgrades/packager_v3_to_stream_v2.yaml @@ -11,7 +11,7 @@ document: modulemd version: 2 data: name: foo - stream: "latest" + stream: "older" summary: An example module description: >- A module for the demonstration of the metadata format. Also, the obligatory lorem diff --git a/yaml_specs/modulemd_packager_v3.yaml b/yaml_specs/modulemd_packager_v3.yaml index 46a575729..41a7b2d83 100644 --- a/yaml_specs/modulemd_packager_v3.yaml +++ b/yaml_specs/modulemd_packager_v3.yaml @@ -188,9 +188,13 @@ data: # Type: OPTIONAL arches: [i686, x86_64] - # Alternate example with no dependencies + # Alternate example with no dependencies, but a different stream name. - context: CTX2 platform: f33 + # stream: + # An override to the stream name defined by the module (or the + # buildsystem, if not specified in data.stream). + stream: "older" # references: # References to external resources, typically upstream