From d891583e0c3f8474394152e5a2538180dae7286b Mon Sep 17 00:00:00 2001 From: Jaroslav Mracek Date: Thu, 1 Sep 2016 22:57:51 +0200 Subject: [PATCH 1/3] Refactor arch_filter() to return including data if arch unset --- libcomps/src/comps_doc.c | 9 +++------ libcomps/src/comps_doccategory.c | 3 +-- libcomps/src/comps_docenv.c | 6 ++---- libcomps/src/comps_docgroup.c | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/libcomps/src/comps_doc.c b/libcomps/src/comps_doc.c index 65397db..806a363 100644 --- a/libcomps/src/comps_doc.c +++ b/libcomps/src/comps_doc.c @@ -852,8 +852,7 @@ COMPS_Doc* comps_doc_arch_filter(COMPS_Doc *source, COMPS_ObjList *arches) { list = comps_doc_categories(source); for (COMPS_ObjListIt *it = list->first; it != NULL; it = it->next) { arches2 = comps_doccategory_arches((COMPS_DocCategory*)it->comps_obj); - if (!arches2) continue; - if (__comps_objlist_intersected(arches, arches2)) { + if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) { cat = comps_doccategory_arch_filter((COMPS_DocCategory*)it->comps_obj, arches); comps_doc_add_category(ret, cat); @@ -864,8 +863,7 @@ COMPS_Doc* comps_doc_arch_filter(COMPS_Doc *source, COMPS_ObjList *arches) { list = comps_doc_groups(source); for (COMPS_ObjListIt *it = list->first; it != NULL; it = it->next) { arches2 = comps_docgroup_arches((COMPS_DocGroup*)it->comps_obj); - if (!arches2) continue; - if (__comps_objlist_intersected(arches, arches2)) { + if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) { group = comps_docgroup_arch_filter((COMPS_DocGroup*)it->comps_obj, arches); comps_doc_add_group(ret, group); @@ -876,8 +874,7 @@ COMPS_Doc* comps_doc_arch_filter(COMPS_Doc *source, COMPS_ObjList *arches) { list = comps_doc_environments(source); for (COMPS_ObjListIt *it = list->first; it != NULL; it = it->next) { arches2 = comps_docenv_arches((COMPS_DocEnv*)it->comps_obj); - if (!arches2) continue; - if (__comps_objlist_intersected(arches, arches2)) { + if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) { env = comps_docenv_arch_filter((COMPS_DocEnv*)it->comps_obj, arches); comps_doc_add_environment(ret, env); diff --git a/libcomps/src/comps_doccategory.c b/libcomps/src/comps_doccategory.c index 8c02546..6c60826 100644 --- a/libcomps/src/comps_doccategory.c +++ b/libcomps/src/comps_doccategory.c @@ -352,8 +352,7 @@ COMPS_DocCategory* comps_doccategory_arch_filter(COMPS_DocCategory *source, for (COMPS_ObjListIt *it = source->group_ids->first; it != NULL; it = it->next) { arches2 = comps_docgroupid_arches((COMPS_DocGroupId*)it->comps_obj); - if (!arches2) continue; - if (__comps_objlist_intersected(arches, arches2)) { + if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) { comps_doccategory_add_groupid(ret, (COMPS_DocGroupId*) comps_object_copy(it->comps_obj)); } diff --git a/libcomps/src/comps_docenv.c b/libcomps/src/comps_docenv.c index 2b9eabf..d34055b 100644 --- a/libcomps/src/comps_docenv.c +++ b/libcomps/src/comps_docenv.c @@ -453,8 +453,7 @@ COMPS_DocEnv* comps_docenv_arch_filter(COMPS_DocEnv *source, for (COMPS_ObjListIt *it = source->group_list->first; it != NULL; it = it->next) { arches2 = comps_docgroupid_arches((COMPS_DocGroupId*)it->comps_obj); - if (!arches2) continue; - if (__comps_objlist_intersected(arches, arches2)) { + if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) { comps_docenv_add_groupid(ret, (COMPS_DocGroupId*) comps_object_copy(it->comps_obj)); } @@ -463,8 +462,7 @@ COMPS_DocEnv* comps_docenv_arch_filter(COMPS_DocEnv *source, for (COMPS_ObjListIt *it = source->option_list->first; it != NULL; it = it->next) { arches2 = comps_docgroupid_arches((COMPS_DocGroupId*)it->comps_obj); - if (!arches2) continue; - if (__comps_objlist_intersected(arches, arches2)) { + if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) { comps_docenv_add_optionid(ret, (COMPS_DocGroupId*) comps_object_copy(it->comps_obj)); } diff --git a/libcomps/src/comps_docgroup.c b/libcomps/src/comps_docgroup.c index e9b0bb3..f305ffd 100644 --- a/libcomps/src/comps_docgroup.c +++ b/libcomps/src/comps_docgroup.c @@ -434,7 +434,7 @@ COMPS_DocGroup* comps_docgroup_arch_filter(COMPS_DocGroup *source, for (COMPS_ObjListIt *it = source->packages->first; it != NULL; it = it->next) { arches2 = comps_docpackage_arches((COMPS_DocGroupPackage*)it->comps_obj); - if (__comps_objlist_intersected(arches, arches2)) { + if ((!arches2) || (__comps_objlist_intersected(arches, arches2))) { comps_docgroup_add_package(ret, (COMPS_DocGroupPackage*) comps_object_copy(it->comps_obj)); } From 582c0026234dc0d008d96caf2f536d6daeb05c45 Mon Sep 17 00:00:00 2001 From: Jaroslav Mracek Date: Mon, 5 Sep 2016 10:30:02 +0200 Subject: [PATCH 2/3] Enlarge uni-test for arch filtering It test new behavior of arch_filter() --- libcomps/src/python/tests/__test.py | 21 ++++++++---- .../src/python/tests/comps/main_arches.xml | 29 ++++++++++++++++- libcomps/tests/check_parse.c | 32 +++++++++---------- libcomps/tests/main_arches.xml | 29 ++++++++++++++++- 4 files changed, 87 insertions(+), 24 deletions(-) diff --git a/libcomps/src/python/tests/__test.py b/libcomps/src/python/tests/__test.py index 3afec15..40c2e83 100644 --- a/libcomps/src/python/tests/__test.py +++ b/libcomps/src/python/tests/__test.py @@ -1029,9 +1029,9 @@ def test_arches(self): comps.fromxml_f("comps/main_arches.xml") filtered = comps.arch_filter(["x86"]) g1_pkgs = ["pkg3", "pkg4", "pkg5", "pkg6", "pkg7"] - c1_gids = ["g1", "g3", "g4", "g6"] - e1_gids = ["g1", "g3", "g4"] - e1_oids = ["o1", "o3", "o4"] + c1_gids = ["g1", "g3", "g4", "g6", "g7"] + e1_gids = ["g1", "g3", "g4", "g6"] + e1_oids = ["o1", "o3", "o4", "o6"] x = 0 for pkg in filtered.groups[0].packages: self.assertTrue(g1_pkgs[x] == pkg.name) @@ -1048,12 +1048,21 @@ def test_arches(self): for oid in filtered.environments[0].option_ids: self.assertTrue(e1_oids[x] == oid.name) x +=1 - empty_comps = libcomps.Comps() + test_comps = libcomps.Comps() + env1 = libcomps.Environment(id='env4', name='env4') + env1.option_ids.append("o5") + group1 = libcomps.Group(id='group4', name='group4') + group1.biarchonly = False + group_id = libcomps.GroupId(name='g1') + c1 = libcomps.Category(id='cat4', name='cat4') + c1.group_ids.append(group_id) + test_comps.environments.append(env1) + test_comps.groups.append(group1) + test_comps.categories.append(c1) comps3 = comps.arch_filter(["unknown"]) - self.assertTrue(empty_comps == comps3) + self.assertTrue(test_comps == comps3) comps4 = comps.arch_filter(["x86", "x86_64", "s390"]) - comps4.environments[2].option_ids.append("o5") self.assertTrue(comps == comps4) s = comps.toxml_str(xml_options = {"arch_output":True}) diff --git a/libcomps/src/python/tests/comps/main_arches.xml b/libcomps/src/python/tests/comps/main_arches.xml index b21c146..4d06658 100644 --- a/libcomps/src/python/tests/comps/main_arches.xml +++ b/libcomps/src/python/tests/comps/main_arches.xml @@ -11,7 +11,7 @@ pkg4 pkg5 pkg6 - pkg7 + pkg7 @@ -28,6 +28,13 @@ pkg7 + + group4 + group4 + + pkg1 + + cat1 cat1 @@ -38,6 +45,7 @@ g4 g5 g6 + g7 @@ -53,6 +61,13 @@ g1 + + + cat4 + cat4 + + g1 + env1 @@ -63,6 +78,7 @@ g3 g4 g5 + g6 o1 @@ -70,6 +86,7 @@ o3 o4 o5 + o6 @@ -85,6 +102,16 @@ env3 env3 + + g1 + + + o5 + + + + env4 + env4 g1 diff --git a/libcomps/tests/check_parse.c b/libcomps/tests/check_parse.c index 32658ee..fcc0a66 100644 --- a/libcomps/tests/check_parse.c +++ b/libcomps/tests/check_parse.c @@ -529,24 +529,24 @@ START_TEST(test_arch) COMPS_Str *str; int x; COMPS_ObjListIt *it; - char *grps[3][4] = {{"group1", "group3", NULL, NULL}, - {"group1", "group2", "group3", NULL}, - {"group3", NULL, NULL, NULL}}; + char *grps[3][5] = {{"group1", "group3", "group4", NULL, NULL}, + {"group1", "group2", "group3", "group4", NULL}, + {"group3", "group4", NULL, NULL, NULL}}; char *g1_pkgs[3][8] = {{"pkg3", "pkg4", "pkg5", "pkg6", "pkg7", NULL, NULL, NULL}, - {"pkg3", "pkg4", NULL, NULL, NULL, NULL, NULL, NULL}, + {"pkg3", "pkg4", "pkg7", NULL, NULL, NULL, NULL, NULL}, {"pkg1", "pkg2", "pkg3", "pkg4", "pkg5", "pkg6", "pkg7", NULL}}; - char *cats[3][4] = {{"cat1", NULL, NULL, NULL}, - {"cat1", "cat2", NULL, NULL}, - {"cat3", NULL, NULL, NULL}}; - char *c1_gids[3][8] = {{"g1", "g3", "g4", "g6", NULL, NULL, NULL, NULL}, - {"g1", "g2", "g4", "g5", NULL, NULL, NULL, NULL}, - {"g4", "g5", "g6", NULL, NULL, NULL, NULL, NULL}}; + char *cats[3][5] = {{"cat1", "cat4", NULL, NULL, NULL}, + {"cat1", "cat2", "cat4", NULL, NULL}, + {"cat3", "cat4", NULL, NULL, NULL}}; + char *c1_gids[3][9] = {{"g1", "g3", "g4", "g6", "g7", NULL, NULL, NULL, NULL}, + {"g1", "g2", "g4", "g5", "g7", NULL, NULL, NULL, NULL}, + {"g4", "g5", "g6", "g7", NULL, NULL, NULL, NULL, NULL}}; - char *envs[3][4] = {{"env1", NULL, NULL, NULL}, - {"env1", "env2", "env3", NULL}, - {"env1", "env2", NULL, NULL}}; + char *envs[3][5] = {{"env1", "env4", NULL, NULL, NULL}, + {"env1", "env2", "env3", "env4", NULL}, + {"env1", "env2", "env4", NULL, NULL}}; char *e1_gids[3][8] = {{"g1", "g3", "g4", NULL, NULL, NULL, NULL, NULL}, {"g1", "g2", "g5", NULL, NULL, NULL, NULL, NULL}, {"g2", "g4", NULL, NULL, NULL,NULL, NULL, NULL}}; @@ -571,7 +571,7 @@ START_TEST(test_arch) COMPS_OBJECT_DESTROY(arches); list = comps_doc_groups(doc2); - ck_assert(list->len == 2); + ck_assert(list->len == 3); for (it = list->first, x=0; it != NULL; it = it->next, x++) { g = (COMPS_DocGroup*)it->comps_obj; str = (COMPS_Str*)comps_docgroup_get_id(g); @@ -591,7 +591,7 @@ START_TEST(test_arch) COMPS_OBJECT_DESTROY(list); list = comps_doc_categories(doc2); - ck_assert(list->len == 1); + ck_assert(list->len == 2); for (it = list->first, x=0; it != NULL; it = it->next, x++) { g = (COMPS_DocCategory*)it->comps_obj; str = (COMPS_Str*)comps_doccategory_get_id(g); @@ -611,7 +611,7 @@ START_TEST(test_arch) COMPS_OBJECT_DESTROY(list); list = comps_doc_environments(doc2); - ck_assert(list->len == 1); + ck_assert(list->len == 2); for (it = list->first, x=0; it != NULL; it = it->next, x++) { g = (COMPS_DocEnv*)it->comps_obj; str = (COMPS_Str*)comps_docenv_get_id(g); diff --git a/libcomps/tests/main_arches.xml b/libcomps/tests/main_arches.xml index 11c0def..4d06658 100644 --- a/libcomps/tests/main_arches.xml +++ b/libcomps/tests/main_arches.xml @@ -11,7 +11,7 @@ pkg4 pkg5 pkg6 - pkg7 + pkg7 @@ -28,6 +28,13 @@ pkg7 + + group4 + group4 + + pkg1 + + cat1 cat1 @@ -38,6 +45,7 @@ g4 g5 g6 + g7 @@ -53,6 +61,13 @@ g1 + + + cat4 + cat4 + + g1 + env1 @@ -63,6 +78,7 @@ g3 g4 g5 + g6 o1 @@ -70,6 +86,7 @@ o3 o4 o5 + o6 @@ -92,4 +109,14 @@ o5 + + env4 + env4 + + g1 + + + o5 + + From eb4efc415833d88f707dc98e5eb3b49bea9ed5b7 Mon Sep 17 00:00:00 2001 From: Jaroslav Mracek Date: Tue, 6 Sep 2016 14:16:13 +0200 Subject: [PATCH 3/3] Allow arch splitting by comma This format is used in RHEL --- libcomps/src/comps_elem.c | 4 ++-- libcomps/src/python/tests/comps/main_arches.xml | 10 +++++----- libcomps/tests/main_arches.xml | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libcomps/src/comps_elem.c b/libcomps/src/comps_elem.c index fb181b3..359fbd0 100644 --- a/libcomps/src/comps_elem.c +++ b/libcomps/src/comps_elem.c @@ -438,10 +438,10 @@ COMPS_ObjList * __comps_split_arches(char *arches) { COMPS_ObjList *list; char *pch; list = COMPS_OBJECT_CREATE(COMPS_ObjList, NULL); - pch = strtok(arches, " "); + pch = strtok(arches, " ,"); while (pch != NULL) { comps_objlist_append_x(list, (COMPS_Object*)comps_str(pch)); - pch = strtok(NULL, " "); + pch = strtok(NULL, " ,"); } return list; } diff --git a/libcomps/src/python/tests/comps/main_arches.xml b/libcomps/src/python/tests/comps/main_arches.xml index 4d06658..6d67766 100644 --- a/libcomps/src/python/tests/comps/main_arches.xml +++ b/libcomps/src/python/tests/comps/main_arches.xml @@ -1,7 +1,7 @@ - + group1 group1 @@ -35,7 +35,7 @@ pkg1 - + cat1 cat1 @@ -69,11 +69,11 @@ g1 - + env1 env1 - g1 + g1 g2 g3 g4 @@ -81,7 +81,7 @@ g6 - o1 + o1 o2 o3 o4 diff --git a/libcomps/tests/main_arches.xml b/libcomps/tests/main_arches.xml index 4d06658..6d67766 100644 --- a/libcomps/tests/main_arches.xml +++ b/libcomps/tests/main_arches.xml @@ -1,7 +1,7 @@ - + group1 group1 @@ -35,7 +35,7 @@ pkg1 - + cat1 cat1 @@ -69,11 +69,11 @@ g1 - + env1 env1 - g1 + g1 g2 g3 g4 @@ -81,7 +81,7 @@ g6 - o1 + o1 o2 o3 o4