@@ -780,79 +780,133 @@ modulemd_packager_v3_to_defaults (ModulemdPackagerV3 *self,
780780 return TRUE;
781781}
782782
783- ModulemdModuleStreamV2 *
784- modulemd_packager_v3_to_stream_v2 (ModulemdPackagerV3 * self , GError * * error )
783+
784+ static void
785+ copy_packager_v3_common_to_stream_v2 (ModulemdModuleStreamV2 * stream_v2 ,
786+ ModulemdPackagerV3 * packager_v3 )
785787{
786- g_autoptr (ModulemdModuleStreamV2 ) v2_stream = NULL ;
787- g_autoptr (ModulemdDependencies ) deps = NULL ;
788788 g_autoptr (ModulemdProfile ) profile = NULL ;
789- g_auto (GStrv ) modules = NULL ;
790- g_auto (GStrv ) contexts = NULL ;
791- g_autoptr (GError ) nested_error = NULL ;
792- ModulemdBuildopts * buildopts = NULL ;
793- ModulemdBuildConfig * bc ;
794789 GHashTableIter iter ;
795790 gpointer value ;
796791
797- g_return_val_if_fail (error == NULL || * error == NULL , NULL );
798- g_return_val_if_fail (MODULEMD_IS_PACKAGER_V3 (self ), NULL );
799-
800- v2_stream = modulemd_module_stream_v2_new (
801- modulemd_packager_v3_get_module_name (self ),
802- modulemd_packager_v3_get_stream_name (self ));
803-
804792 modulemd_module_stream_v2_set_summary (
805- v2_stream , modulemd_packager_v3_get_summary (self ));
793+ stream_v2 , modulemd_packager_v3_get_summary (packager_v3 ));
806794
807795 modulemd_module_stream_v2_set_description (
808- v2_stream , modulemd_packager_v3_get_description (self ));
796+ stream_v2 , modulemd_packager_v3_get_description (packager_v3 ));
809797
810798 /* Packager v3 "license" is optional. Stream v2 "license" is required
811799 * Fill in the default Packager v3 license if none has been specified.
812800 */
813- if (g_hash_table_size (self -> module_licenses ) == 0 )
801+ if (g_hash_table_size (packager_v3 -> module_licenses ) == 0 )
814802 {
815803 modulemd_module_stream_v2_add_module_license (
816- v2_stream , MMD_PACKAGER_DEFAULT_MODULE_LICENSE );
804+ stream_v2 , MMD_PACKAGER_DEFAULT_MODULE_LICENSE );
817805 }
818806 else
819807 {
820- MODULEMD_REPLACE_SET (v2_stream -> module_licenses , self -> module_licenses );
808+ MODULEMD_REPLACE_SET (stream_v2 -> module_licenses ,
809+ packager_v3 -> module_licenses );
821810 }
822811
823- modulemd_module_stream_v2_set_xmd (v2_stream ,
824- modulemd_packager_v3_get_xmd (self ));
812+ modulemd_module_stream_v2_set_xmd (
813+ stream_v2 , modulemd_packager_v3_get_xmd (packager_v3 ));
825814
826815 modulemd_module_stream_v2_set_community (
827- v2_stream , modulemd_packager_v3_get_community (self ));
816+ stream_v2 , modulemd_packager_v3_get_community (packager_v3 ));
828817
829818 modulemd_module_stream_v2_set_documentation (
830- v2_stream , modulemd_packager_v3_get_documentation (self ));
819+ stream_v2 , modulemd_packager_v3_get_documentation (packager_v3 ));
831820
832821 modulemd_module_stream_v2_set_tracker (
833- v2_stream , modulemd_packager_v3_get_tracker (self ));
822+ stream_v2 , modulemd_packager_v3_get_tracker (packager_v3 ));
834823
835- g_hash_table_iter_init (& iter , self -> profiles );
824+ g_hash_table_iter_init (& iter , packager_v3 -> profiles );
836825 while (g_hash_table_iter_next (& iter , NULL , & value ))
837826 {
838827 profile = modulemd_profile_copy (MODULEMD_PROFILE (value ));
839828 modulemd_profile_unset_default (profile );
840- modulemd_module_stream_v2_add_profile (v2_stream , profile );
829+ modulemd_module_stream_v2_add_profile (stream_v2 , profile );
841830 g_clear_object (& profile );
842831 }
843832
844- modulemd_module_stream_v2_replace_rpm_api (v2_stream , self -> rpm_api );
833+ modulemd_module_stream_v2_replace_rpm_api (stream_v2 , packager_v3 -> rpm_api );
845834
846- modulemd_module_stream_v2_replace_rpm_filters (v2_stream , self -> rpm_filters );
835+ modulemd_module_stream_v2_replace_rpm_filters (stream_v2 ,
836+ packager_v3 -> rpm_filters );
847837
848- COPY_HASHTABLE_BY_VALUE_ADDER (
849- v2_stream , self , rpm_components , modulemd_module_stream_v2_add_component );
838+ COPY_HASHTABLE_BY_VALUE_ADDER (stream_v2 ,
839+ packager_v3 ,
840+ rpm_components ,
841+ modulemd_module_stream_v2_add_component );
850842
851- COPY_HASHTABLE_BY_VALUE_ADDER (v2_stream ,
852- self ,
843+ COPY_HASHTABLE_BY_VALUE_ADDER (stream_v2 ,
844+ packager_v3 ,
853845 module_components ,
854846 modulemd_module_stream_v2_add_component );
847+ }
848+
849+ static void
850+ copy_packager_v3_buildconfig_to_stream_v2 (ModulemdModuleStreamV2 * stream_v2 ,
851+ ModulemdBuildConfig * bc )
852+ {
853+ g_autoptr (ModulemdDependencies ) deps = NULL ;
854+ g_auto (GStrv ) modules = NULL ;
855855
856+ modulemd_module_stream_v2_set_buildopts (
857+ stream_v2 , modulemd_build_config_get_buildopts (bc ));
858+
859+ deps = modulemd_dependencies_new ();
860+
861+ modulemd_dependencies_add_buildtime_stream (
862+ deps , "platform" , modulemd_build_config_get_platform (bc ));
863+ modulemd_dependencies_add_runtime_stream (
864+ deps , "platform" , modulemd_build_config_get_platform (bc ));
865+
866+ modules = modulemd_build_config_get_buildtime_modules_as_strv (bc );
867+ for (guint j = 0 ; j < g_strv_length (modules ); j ++ )
868+ {
869+ modulemd_dependencies_add_buildtime_stream (
870+ deps ,
871+ modules [j ],
872+ modulemd_build_config_get_buildtime_requirement_stream (bc ,
873+ modules [j ]));
874+ }
875+ g_clear_pointer (& modules , g_strfreev );
876+
877+ modules = modulemd_build_config_get_runtime_modules_as_strv (bc );
878+ for (guint j = 0 ; j < g_strv_length (modules ); j ++ )
879+ {
880+ modulemd_dependencies_add_runtime_stream (
881+ deps ,
882+ modules [j ],
883+ modulemd_build_config_get_runtime_requirement_stream (bc , modules [j ]));
884+ }
885+ g_clear_pointer (& modules , g_strfreev );
886+
887+ modulemd_module_stream_v2_add_dependencies (stream_v2 , deps );
888+ g_clear_object (& deps );
889+ }
890+
891+
892+ ModulemdModuleStreamV2 *
893+ modulemd_packager_v3_to_stream_v2 (ModulemdPackagerV3 * self , GError * * error )
894+ {
895+ g_autoptr (ModulemdModuleStreamV2 ) v2_stream = NULL ;
896+ g_auto (GStrv ) contexts = NULL ;
897+ g_autoptr (GError ) nested_error = NULL ;
898+ ModulemdBuildopts * buildopts = NULL ;
899+ ModulemdBuildConfig * bc ;
900+
901+ g_return_val_if_fail (error == NULL || * error == NULL , NULL );
902+ g_return_val_if_fail (MODULEMD_IS_PACKAGER_V3 (self ), NULL );
903+
904+ v2_stream = modulemd_module_stream_v2_new (
905+ modulemd_packager_v3_get_module_name (self ),
906+ modulemd_packager_v3_get_stream_name (self ));
907+
908+ /* set attributes that are the same for all streams */
909+ copy_packager_v3_common_to_stream_v2 (v2_stream , self );
856910
857911 /* get the list of packager build configuration contexts */
858912 contexts = modulemd_packager_v3_get_build_config_contexts_as_strv (self );
@@ -865,56 +919,25 @@ modulemd_packager_v3_to_stream_v2 (ModulemdPackagerV3 *self, GError **error)
865919 contexts [0 ]);
866920 }
867921
868- /* map each BuildConfig object to a Dependencies object */
922+ /* map each BuildConfig object to a Dependencies object within the same StreamV2 object */
869923 for (guint i = 0 ; i < g_strv_length (contexts ); i ++ )
870924 {
871925 bc = modulemd_packager_v3_get_build_config (self , contexts [i ]);
872926
873927 if (i == 0 )
874928 {
875- /* Use the buildopts from the first build configuration to */
929+ /* Save the buildopts from the first build configuration to */
876930 /* set the stream buildopts. */
877931 buildopts = modulemd_build_config_get_buildopts (bc );
878932 }
879933
880- deps = modulemd_dependencies_new ();
881-
882- modulemd_dependencies_add_buildtime_stream (
883- deps , "platform" , modulemd_build_config_get_platform (bc ));
884- modulemd_dependencies_add_runtime_stream (
885- deps , "platform" , modulemd_build_config_get_platform (bc ));
886-
887- modules = modulemd_build_config_get_buildtime_modules_as_strv (bc );
888- for (guint j = 0 ; j < g_strv_length (modules ); j ++ )
889- {
890- modulemd_dependencies_add_buildtime_stream (
891- deps ,
892- modules [j ],
893- modulemd_build_config_get_buildtime_requirement_stream (
894- bc , modules [j ]));
895- }
896- g_clear_pointer (& modules , g_strfreev );
897-
898- modules = modulemd_build_config_get_runtime_modules_as_strv (bc );
899- for (guint j = 0 ; j < g_strv_length (modules ); j ++ )
900- {
901- modulemd_dependencies_add_runtime_stream (
902- deps ,
903- modules [j ],
904- modulemd_build_config_get_runtime_requirement_stream (bc ,
905- modules [j ]));
906- }
907- g_clear_pointer (& modules , g_strfreev );
908-
909- modulemd_module_stream_v2_add_dependencies (v2_stream , deps );
910- g_clear_object (& deps );
934+ /* set attributes that are unique per build configuration */
935+ copy_packager_v3_buildconfig_to_stream_v2 (v2_stream , bc );
911936 }
912937 g_clear_pointer (& contexts , g_strfreev );
913938
914- if (buildopts )
915- {
916- modulemd_module_stream_v2_set_buildopts (v2_stream , buildopts );
917- }
939+ /* set the saved buildopts from the first build configuration */
940+ modulemd_module_stream_v2_set_buildopts (v2_stream , buildopts );
918941
919942 if (!modulemd_module_stream_validate (MODULEMD_MODULE_STREAM (v2_stream ),
920943 & nested_error ))
@@ -990,14 +1013,9 @@ modulemd_packager_v3_convert_to_index (ModulemdPackagerV3 *self,
9901013 g_auto (GStrv ) contexts = NULL ;
9911014 g_autoptr (ModulemdModuleIndex ) index = NULL ;
9921015 g_autoptr (ModulemdModuleStreamV2 ) v2_stream = NULL ;
993- g_autoptr (ModulemdProfile ) profile = NULL ;
994- g_autoptr (ModulemdDependencies ) deps = NULL ;
9951016 g_autoptr (ModulemdDefaults ) defaults = NULL ;
996- g_auto (GStrv ) modules = NULL ;
9971017 g_autoptr (GError ) nested_error = NULL ;
9981018 ModulemdBuildConfig * bc ;
999- GHashTableIter iter ;
1000- gpointer value ;
10011019
10021020 g_return_val_if_fail (error == NULL || * error == NULL , NULL );
10031021 g_return_val_if_fail (MODULEMD_IS_PACKAGER_V3 (self ), NULL );
@@ -1031,103 +1049,10 @@ modulemd_packager_v3_convert_to_index (ModulemdPackagerV3 *self,
10311049 contexts [i ]);
10321050
10331051 /* set attributes that are the same for all streams */
1052+ copy_packager_v3_common_to_stream_v2 (v2_stream , self );
10341053
1035- modulemd_module_stream_v2_set_summary (
1036- v2_stream , modulemd_packager_v3_get_summary (self ));
1037-
1038- modulemd_module_stream_v2_set_description (
1039- v2_stream , modulemd_packager_v3_get_description (self ));
1040-
1041- /* Packager v3 "license" is optional. Stream v2 "license" is required
1042- * Fill in the default Packager v3 license if none has been specified.
1043- */
1044- if (g_hash_table_size (self -> module_licenses ) == 0 )
1045- {
1046- modulemd_module_stream_v2_add_module_license (
1047- v2_stream , MMD_PACKAGER_DEFAULT_MODULE_LICENSE );
1048- }
1049- else
1050- {
1051- MODULEMD_REPLACE_SET (v2_stream -> module_licenses ,
1052- self -> module_licenses );
1053- }
1054-
1055- modulemd_module_stream_v2_set_xmd (v2_stream ,
1056- modulemd_packager_v3_get_xmd (self ));
1057-
1058- modulemd_module_stream_v2_set_community (
1059- v2_stream , modulemd_packager_v3_get_community (self ));
1060-
1061- modulemd_module_stream_v2_set_documentation (
1062- v2_stream , modulemd_packager_v3_get_documentation (self ));
1063-
1064- modulemd_module_stream_v2_set_tracker (
1065- v2_stream , modulemd_packager_v3_get_tracker (self ));
1066-
1067- g_hash_table_iter_init (& iter , self -> profiles );
1068- while (g_hash_table_iter_next (& iter , NULL , & value ))
1069- {
1070- profile = modulemd_profile_copy (MODULEMD_PROFILE (value ));
1071- modulemd_profile_unset_default (profile );
1072- modulemd_module_stream_v2_add_profile (v2_stream , profile );
1073- g_clear_object (& profile );
1074- }
1075-
1076- modulemd_module_stream_v2_replace_rpm_api (v2_stream , self -> rpm_api );
1077-
1078- modulemd_module_stream_v2_replace_rpm_filters (v2_stream ,
1079- self -> rpm_filters );
1080-
1081- COPY_HASHTABLE_BY_VALUE_ADDER (v2_stream ,
1082- self ,
1083- rpm_components ,
1084- modulemd_module_stream_v2_add_component );
1085-
1086- COPY_HASHTABLE_BY_VALUE_ADDER (v2_stream ,
1087- self ,
1088- module_components ,
1089- modulemd_module_stream_v2_add_component );
1090-
1091-
1092- /* set attributes that are the unique per build configuration */
1093-
1094- if (modulemd_build_config_get_buildopts (bc ))
1095- {
1096- modulemd_module_stream_v2_set_buildopts (
1097- v2_stream , modulemd_build_config_get_buildopts (bc ));
1098- }
1099-
1100- deps = modulemd_dependencies_new ();
1101-
1102- modulemd_dependencies_add_buildtime_stream (
1103- deps , "platform" , modulemd_build_config_get_platform (bc ));
1104- modulemd_dependencies_add_runtime_stream (
1105- deps , "platform" , modulemd_build_config_get_platform (bc ));
1106-
1107- modules = modulemd_build_config_get_buildtime_modules_as_strv (bc );
1108- for (guint j = 0 ; j < g_strv_length (modules ); j ++ )
1109- {
1110- modulemd_dependencies_add_buildtime_stream (
1111- deps ,
1112- modules [j ],
1113- modulemd_build_config_get_buildtime_requirement_stream (
1114- bc , modules [j ]));
1115- }
1116- g_clear_pointer (& modules , g_strfreev );
1117-
1118- modules = modulemd_build_config_get_runtime_modules_as_strv (bc );
1119- for (guint j = 0 ; j < g_strv_length (modules ); j ++ )
1120- {
1121- modulemd_dependencies_add_runtime_stream (
1122- deps ,
1123- modules [j ],
1124- modulemd_build_config_get_runtime_requirement_stream (bc ,
1125- modules [j ]));
1126- }
1127- g_clear_pointer (& modules , g_strfreev );
1128-
1129- modulemd_module_stream_v2_add_dependencies (v2_stream , deps );
1130- g_clear_object (& deps );
1054+ /* set attributes that are unique per build configuration */
1055+ copy_packager_v3_buildconfig_to_stream_v2 (v2_stream , bc );
11311056
11321057 if (!modulemd_module_stream_validate (MODULEMD_MODULE_STREAM (v2_stream ),
11331058 & nested_error ))
0 commit comments