Skip to content

Commit

Permalink
Add support for stream overrides in configurations
Browse files Browse the repository at this point in the history
Fixes: fedora-modularity#599

Signed-off-by: Stephen Gallagher <[email protected]>
  • Loading branch information
sgallagher committed Jul 26, 2022
1 parent a0741ff commit d9cb3ba
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 4 deletions.
29 changes: 29 additions & 0 deletions modulemd/include/modulemd-2.0/modulemd-build-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
44 changes: 44 additions & 0 deletions modulemd/modulemd-build-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct _ModulemdBuildConfig

gchar *context;
gchar *platform;
gchar *stream;
GHashTable *requires; /* hashtable<string, string> */
GHashTable *buildrequires; /* hashtable<string, string> */
ModulemdBuildopts *buildopts;
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"))
{
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions modulemd/modulemd-packager-v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 5 additions & 1 deletion modulemd/tests/test-modulemd-packager-v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ document: modulemd
version: 2
data:
name: foo
stream: "latest"
stream: "older"
context: CTX2
summary: An example module
description: >-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion yaml_specs/modulemd_packager_v3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d9cb3ba

Please sign in to comment.