Skip to content

Commit 0860fee

Browse files
mmathesiussgallagher
authored andcommitted
Restore accidentally dropped ability for ModuleStream.read_*() functions to
transparently read packager-v3 documents, deprecate them in favor of the new Modulemd.read_packager_*() functions, and add notes to their documentation about the limitations of the packager-v3 to stream-v2 conversion. Signed-off-by: Merlin Mathesius <[email protected]>
1 parent da1eaee commit 0860fee

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

modulemd/include/modulemd-2.0/modulemd-module-stream.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,23 @@ modulemd_module_stream_new (guint64 mdversion,
138138
*
139139
* Create a #ModulemdModuleStream object from a YAML file.
140140
*
141+
* Note: This function also reads modulemd-packager v2 and v3 documents, which
142+
* are transparently returned as #ModulemdModuleStream (V2) objects. However,
143+
* if a modulemd-packager v3 document (#ModulemdPackagerV3) is encountered and
144+
* it uses buildopts (#ModulemdBuildopts) in one or more build configurations,
145+
* only the buildopts present in the first listed configuration (if any) will be
146+
* applied to the returned #ModulemdModuleStreamV2 object.
147+
*
141148
* Returns: (transfer full): A newly-allocated #ModulemdModuleStream object if
142149
* the YAML file was valid and contained exactly one `document: modulemd`
143150
* subdocument. NULL if the document fails validation or multiple documents are
144151
* encountered and sets @error appropriately. See #ModulemdModuleIndex for
145152
* functions to read in multiple-subdocument YAML.
146153
*
147154
* Since: 2.0
155+
* Deprecated: 2.11: Use modulemd_read_packager_file() instead.
148156
*/
157+
MMD_DEPRECATED_FOR (modulemd_read_packager_file)
149158
ModulemdModuleStream *
150159
modulemd_module_stream_read_file (const gchar *path,
151160
gboolean strict,
@@ -170,14 +179,23 @@ modulemd_module_stream_read_file (const gchar *path,
170179
*
171180
* Create a #ModulemdModuleStream object from a YAML string.
172181
*
182+
* Note: This function also reads modulemd-packager v2 and v3 documents, which
183+
* are transparently returned as #ModulemdModuleStream (V2) objects. However,
184+
* if a modulemd-packager v3 document (#ModulemdPackagerV3) is encountered and
185+
* it uses buildopts (#ModulemdBuildopts) in one or more build configurations,
186+
* only the buildopts present in the first listed configuration (if any) will be
187+
* applied to the returned #ModulemdModuleStreamV2 object.
188+
*
173189
* Returns: (transfer full): A newly-allocated #ModulemdModuleStream object if
174190
* the YAML string was valid and contained exactly one `document: modulemd`
175191
* subdocument. NULL if the document fails validation or multiple documents are
176192
* encountered and sets @error appropriately. See #ModulemdModuleIndex for
177193
* functions to read in multiple-subdocument YAML.
178194
*
179195
* Since: 2.0
196+
* Deprecated: 2.11: Use modulemd_read_packager_string() instead.
180197
*/
198+
MMD_DEPRECATED_FOR (modulemd_read_packager_string)
181199
ModulemdModuleStream *
182200
modulemd_module_stream_read_string (const gchar *yaml_string,
183201
gboolean strict,

modulemd/modulemd-module-stream.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "private/modulemd-module-stream-private.h"
2525
#include "private/modulemd-module-stream-v1-private.h"
2626
#include "private/modulemd-module-stream-v2-private.h"
27+
#include "private/modulemd-packager-v3-private.h"
2728
#include "private/modulemd-subdocument-info-private.h"
2829
#include "private/modulemd-util.h"
2930
#include "private/modulemd-yaml.h"
@@ -258,6 +259,38 @@ modulemd_module_stream_read_yaml (yaml_parser_t *parser,
258259
}
259260
break;
260261

262+
case MD_PACKAGER_VERSION_THREE:
263+
if (doctype == MODULEMD_YAML_DOC_PACKAGER)
264+
{
265+
packager_v3 =
266+
modulemd_packager_v3_parse_yaml (subdoc, &nested_error);
267+
if (!packager_v3)
268+
{
269+
g_propagate_error (error, g_steal_pointer (&nested_error));
270+
return NULL;
271+
}
272+
273+
stream = MODULEMD_MODULE_STREAM (
274+
modulemd_packager_v3_to_stream_v2 (packager_v3, &nested_error));
275+
if (!stream)
276+
{
277+
g_propagate_error (error, g_steal_pointer (&nested_error));
278+
return NULL;
279+
}
280+
281+
g_clear_object (&packager_v3);
282+
}
283+
else
284+
{
285+
g_set_error (error,
286+
MODULEMD_YAML_ERROR,
287+
MMD_YAML_ERROR_PARSE,
288+
"Invalid ModuleStream version: %" PRIu64,
289+
modulemd_subdocument_info_get_mdversion (subdoc));
290+
return NULL;
291+
}
292+
break;
293+
261294
default:
262295
g_set_error (error,
263296
MODULEMD_YAML_ERROR,

modulemd/tests/test-modulemd-modulestream.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ module_stream_test_v2_yaml (void)
652652

653653
GPtrArray *dependencies = NULL;
654654

655+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
655656
stream = modulemd_module_stream_read_string (
656657
"---\n"
657658
"document: modulemd\n"
@@ -794,6 +795,7 @@ module_stream_test_v2_yaml (void)
794795
NULL,
795796
NULL,
796797
&error);
798+
G_GNUC_END_IGNORE_DEPRECATIONS
797799

798800
g_assert_no_error (error);
799801

@@ -1007,6 +1009,7 @@ module_stream_test_v2_yaml (void)
10071009

10081010

10091011
// Validate a trivial modulemd
1012+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
10101013
stream = modulemd_module_stream_read_string (
10111014
"---\n"
10121015
"document: modulemd\n"
@@ -1022,6 +1025,7 @@ module_stream_test_v2_yaml (void)
10221025
NULL,
10231026
NULL,
10241027
&error);
1028+
G_GNUC_END_IGNORE_DEPRECATIONS
10251029

10261030
g_assert_no_error (error);
10271031
g_assert_nonnull (stream);
@@ -1032,8 +1036,10 @@ module_stream_test_v2_yaml (void)
10321036
// Sanity check spec.v2.yaml
10331037
gchar *specV2Path = g_strdup_printf ("%s/yaml_specs/modulemd_stream_v2.yaml",
10341038
g_getenv ("MESON_SOURCE_ROOT"));
1039+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
10351040
stream =
10361041
modulemd_module_stream_read_file (specV2Path, TRUE, NULL, NULL, &error);
1042+
G_GNUC_END_IGNORE_DEPRECATIONS
10371043

10381044
g_assert_no_error (error);
10391045
g_assert_nonnull (stream);
@@ -1051,8 +1057,10 @@ module_packager_v2_sanity (void)
10511057

10521058
g_autofree gchar *specV2Path = g_strdup_printf (
10531059
"%s/yaml_specs/modulemd_packager_v2.yaml", g_getenv ("MESON_SOURCE_ROOT"));
1060+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
10541061
stream =
10551062
modulemd_module_stream_read_file (specV2Path, TRUE, NULL, NULL, &error);
1063+
G_GNUC_END_IGNORE_DEPRECATIONS
10561064
g_assert_no_error (error);
10571065
g_assert_nonnull (stream);
10581066

@@ -1061,6 +1069,29 @@ module_packager_v2_sanity (void)
10611069
}
10621070

10631071

1072+
static void
1073+
module_packager_v3_sanity (void)
1074+
{
1075+
g_autoptr (ModulemdModuleStream) stream = NULL;
1076+
g_autoptr (GError) error = NULL;
1077+
1078+
g_autofree gchar *packagerV3Path = g_strdup_printf (
1079+
"%s/yaml_specs/modulemd_packager_v3.yaml", g_getenv ("MESON_SOURCE_ROOT"));
1080+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
1081+
stream = modulemd_module_stream_read_file (
1082+
packagerV3Path, TRUE, NULL, NULL, &error);
1083+
G_GNUC_END_IGNORE_DEPRECATIONS
1084+
g_assert_no_error (error);
1085+
g_assert_nonnull (stream);
1086+
1087+
/* confirm packager v3 document was returned as stream v2 */
1088+
g_assert_true (MODULEMD_IS_MODULE_STREAM_V2 (stream));
1089+
1090+
g_clear_object (&stream);
1091+
g_clear_pointer (&packagerV3Path, g_free);
1092+
}
1093+
1094+
10641095
static void
10651096
module_stream_v1_test_rpm_artifacts (void)
10661097
{
@@ -2753,8 +2784,10 @@ module_stream_v1_test_depends_on_stream (void)
27532784

27542785
path = g_strdup_printf ("%s/dependson_v1.yaml", g_getenv ("TEST_DATA_PATH"));
27552786
g_assert_nonnull (path);
2787+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
27562788
stream = modulemd_module_stream_read_file (
27572789
path, TRUE, module_name, module_stream, &error);
2790+
G_GNUC_END_IGNORE_DEPRECATIONS
27582791
g_assert_nonnull (stream);
27592792

27602793
g_assert_true (
@@ -2785,8 +2818,10 @@ module_stream_v2_test_depends_on_stream (void)
27852818

27862819
path = g_strdup_printf ("%s/dependson_v2.yaml", g_getenv ("TEST_DATA_PATH"));
27872820
g_assert_nonnull (path);
2821+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
27882822
stream = modulemd_module_stream_read_file (
27892823
path, TRUE, module_name, module_stream, &error);
2824+
G_GNUC_END_IGNORE_DEPRECATIONS
27902825
g_assert_nonnull (stream);
27912826

27922827
g_assert_true (
@@ -2826,8 +2861,10 @@ module_stream_test_validate_buildafter (void)
28262861
g_getenv ("TEST_DATA_PATH"),
28272862
version);
28282863
g_assert_nonnull (path);
2864+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
28292865
stream =
28302866
modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
2867+
G_GNUC_END_IGNORE_DEPRECATIONS
28312868
g_assert_nonnull (stream);
28322869
g_assert_null (error);
28332870
g_clear_pointer (&path, g_free);
@@ -2841,8 +2878,10 @@ module_stream_test_validate_buildafter (void)
28412878
g_getenv ("TEST_DATA_PATH"),
28422879
version);
28432880
g_assert_nonnull (path);
2881+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
28442882
stream =
28452883
modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
2884+
G_GNUC_END_IGNORE_DEPRECATIONS
28462885
g_assert_error (error, MODULEMD_ERROR, MMD_ERROR_VALIDATE);
28472886
g_assert_null (stream);
28482887
g_clear_error (&error);
@@ -2856,8 +2895,10 @@ module_stream_test_validate_buildafter (void)
28562895
g_getenv ("TEST_DATA_PATH"),
28572896
version);
28582897
g_assert_nonnull (path);
2898+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
28592899
stream =
28602900
modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
2901+
G_GNUC_END_IGNORE_DEPRECATIONS
28612902
g_assert_error (error, MODULEMD_ERROR, MMD_ERROR_VALIDATE);
28622903
g_assert_null (stream);
28632904
g_clear_error (&error);
@@ -2870,8 +2911,10 @@ module_stream_test_validate_buildafter (void)
28702911
g_getenv ("TEST_DATA_PATH"),
28712912
version);
28722913
g_assert_nonnull (path);
2914+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
28732915
stream =
28742916
modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
2917+
G_GNUC_END_IGNORE_DEPRECATIONS
28752918
g_assert_error (error, MODULEMD_ERROR, MMD_ERROR_VALIDATE);
28762919
g_assert_null (stream);
28772920
g_clear_error (&error);
@@ -2901,8 +2944,10 @@ module_stream_test_validate_buildarches (void)
29012944
g_getenv ("TEST_DATA_PATH"),
29022945
version);
29032946
g_assert_nonnull (path);
2947+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
29042948
stream =
29052949
modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
2950+
G_GNUC_END_IGNORE_DEPRECATIONS
29062951
g_assert_nonnull (stream);
29072952
g_assert_null (error);
29082953
g_clear_pointer (&path, g_free);
@@ -2916,8 +2961,10 @@ module_stream_test_validate_buildarches (void)
29162961
g_getenv ("TEST_DATA_PATH"),
29172962
version);
29182963
g_assert_nonnull (path);
2964+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
29192965
stream =
29202966
modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
2967+
G_GNUC_END_IGNORE_DEPRECATIONS
29212968
g_assert_nonnull (stream);
29222969
g_assert_null (error);
29232970
g_clear_pointer (&path, g_free);
@@ -2931,8 +2978,10 @@ module_stream_test_validate_buildarches (void)
29312978
g_getenv ("TEST_DATA_PATH"),
29322979
version);
29332980
g_assert_nonnull (path);
2981+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
29342982
stream =
29352983
modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
2984+
G_GNUC_END_IGNORE_DEPRECATIONS
29362985
g_assert_nonnull (stream);
29372986
g_assert_null (error);
29382987
g_clear_pointer (&path, g_free);
@@ -2946,8 +2995,10 @@ module_stream_test_validate_buildarches (void)
29462995
g_getenv ("TEST_DATA_PATH"),
29472996
version);
29482997
g_assert_nonnull (path);
2998+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
29492999
stream =
29503000
modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
3001+
G_GNUC_END_IGNORE_DEPRECATIONS
29513002
g_assert_nonnull (stream);
29523003
g_assert_null (error);
29533004
g_clear_pointer (&path, g_free);
@@ -2961,8 +3012,10 @@ module_stream_test_validate_buildarches (void)
29613012
g_getenv ("TEST_DATA_PATH"),
29623013
version);
29633014
g_assert_nonnull (path);
3015+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
29643016
stream =
29653017
modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
3018+
G_GNUC_END_IGNORE_DEPRECATIONS
29663019
g_assert_error (error, MODULEMD_ERROR, MMD_ERROR_VALIDATE);
29673020
g_assert_null (stream);
29683021
g_clear_error (&error);
@@ -3014,8 +3067,10 @@ module_stream_test_unicode_desc (void)
30143067
version);
30153068
g_assert_nonnull (path);
30163069

3070+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
30173071
stream =
30183072
modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
3073+
G_GNUC_END_IGNORE_DEPRECATIONS
30193074
g_assert_nonnull (stream);
30203075
g_assert_no_error (error);
30213076
g_clear_object (&stream);
@@ -3038,7 +3093,9 @@ module_stream_v1_test_xmd_issue_274 (void)
30383093
g_strdup_printf ("%s/stream_unicode_v1.yaml", g_getenv ("TEST_DATA_PATH"));
30393094
g_assert_nonnull (path);
30403095

3096+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
30413097
stream = modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
3098+
G_GNUC_END_IGNORE_DEPRECATIONS
30423099
g_assert_nonnull (stream);
30433100
g_assert_no_error (error);
30443101
g_assert_cmpint (modulemd_module_stream_get_mdversion (stream),
@@ -3134,7 +3191,9 @@ module_stream_v2_test_xmd_issue_290_with_example (void)
31343191

31353192
path = g_strdup_printf ("%s/290.yaml", g_getenv ("TEST_DATA_PATH"));
31363193
g_assert_nonnull (path);
3194+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
31373195
stream = modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
3196+
G_GNUC_END_IGNORE_DEPRECATIONS
31383197
g_assert_nonnull (stream);
31393198
g_assert_no_error (error);
31403199

@@ -3279,8 +3338,10 @@ module_stream_v1_regression_content_license (void)
32793338
" - bar\n"
32803339
"...\n";
32813340

3341+
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
32823342
stream = modulemd_module_stream_read_string (
32833343
content_first, TRUE, NULL, NULL, &error);
3344+
G_GNUC_END_IGNORE_DEPRECATIONS
32843345
g_assert_no_error (error);
32853346
g_assert_nonnull (stream);
32863347
g_assert_true (MODULEMD_IS_MODULE_STREAM_V1 (stream));
@@ -3396,6 +3457,9 @@ main (int argc, char *argv[])
33963457
g_test_add_func ("/modulemd/v2/packager/v2_sanity",
33973458
module_packager_v2_sanity);
33983459

3460+
g_test_add_func ("/modulemd/v2/packager/v3_sanity",
3461+
module_packager_v3_sanity);
3462+
33993463
g_test_add_func ("/modulemd/v2/modulestream/upgrade_v1_to_v2",
34003464
module_stream_test_upgrade_v1_to_v2);
34013465

0 commit comments

Comments
 (0)