| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include "phoenix_color.h" | ||
| 8 | #include "parser_toml.h" | ||
| 9 | #include "project_generator_load.h" | ||
| 10 | |||
| 11 | ///Split dependencies strings into name, min_version, max_version and fill the map of dependencies | ||
| 12 | /** @param[out] config : project configuration to fill | ||
| 13 | * @param vecDependencies : list of dependencies strings | ||
| 14 | * @return true on success, false otherwise | ||
| 15 | */ | ||
| 16 | 3 | bool project_generator_split_dependencies(ProjectConfig & config, std::vector<PString> & vecDependencies){ | |
| 17 |
2/2✓ Branch 0 (107→4) taken 10 times.
✓ Branch 1 (107→108) taken 3 times.
|
16 | for(const PString & depStr : vecDependencies){ |
| 18 |
3/3✓ Branch 0 (6→7) taken 10 times.
✓ Branch 2 (7→8) taken 10 times.
✓ Branch 4 (8→9) taken 10 times.
|
10 | PString name(""), min_version(""), max_version(""); |
| 19 |
1/1✓ Branch 0 (9→10) taken 10 times.
|
10 | std::istringstream iss(depStr); |
| 20 | 10 | std::vector<PString> depValues; | |
| 21 |
1/1✓ Branch 0 (11→12) taken 10 times.
|
10 | PString token; |
| 22 |
5/5✓ Branch 0 (13→14) taken 27 times.
✓ Branch 2 (14→15) taken 37 times.
✓ Branch 4 (15→16) taken 37 times.
✓ Branch 6 (16→13) taken 27 times.
✓ Branch 7 (16→17) taken 10 times.
|
37 | while (iss >> token){depValues.push_back(token);} |
| 23 |
1/2✓ Branch 0 (18→19) taken 10 times.
✗ Branch 1 (18→85) not taken.
|
10 | if(!depValues.empty()){ |
| 24 |
1/1✓ Branch 0 (20→21) taken 10 times.
|
10 | name = depValues[0]; |
| 25 |
2/2✓ Branch 0 (83→22) taken 17 times.
✓ Branch 1 (83→84) taken 9 times.
|
26 | for(size_t i=1; i<depValues.size(); ++i){ |
| 26 |
4/4✓ Branch 0 (23→24) taken 17 times.
✓ Branch 2 (24→25) taken 17 times.
✓ Branch 4 (26→27) taken 1 times.
✓ Branch 5 (26→31) taken 16 times.
|
17 | if(depValues[i].isSameBegining("==")) { |
| 27 | // User specifies the exact version | ||
| 28 |
1/1✓ Branch 0 (28→29) taken 1 times.
|
1 | min_version = depValues[i]; |
| 29 |
1/1✓ Branch 0 (29→30) taken 1 times.
|
1 | max_version = ""; |
| 30 | 1 | break; | |
| 31 | } | ||
| 32 |
12/18✓ Branch 0 (32→33) taken 16 times.
✓ Branch 2 (33→34) taken 16 times.
✓ Branch 4 (34→35) taken 8 times.
✓ Branch 5 (34→39) taken 8 times.
✓ Branch 6 (36→37) taken 8 times.
✓ Branch 8 (37→38) taken 8 times.
✗ Branch 10 (38→39) not taken.
✓ Branch 11 (38→40) taken 8 times.
✓ Branch 12 (41→42) taken 8 times.
✓ Branch 13 (41→43) taken 8 times.
✓ Branch 14 (43→44) taken 16 times.
✗ Branch 15 (43→45) not taken.
✓ Branch 16 (45→46) taken 8 times.
✓ Branch 17 (45→56) taken 8 times.
✗ Branch 18 (113→114) not taken.
✗ Branch 19 (113→115) not taken.
✗ Branch 20 (117→118) not taken.
✗ Branch 21 (117→119) not taken.
|
16 | if(depValues[i].isSameBegining(">=") || depValues[i].isSameBegining(">")) { |
| 33 |
1/1✓ Branch 0 (47→48) taken 8 times.
|
8 | min_version = depValues[i]; |
| 34 |
3/6✓ Branch 0 (49→50) taken 8 times.
✗ Branch 1 (49→53) not taken.
✓ Branch 2 (51→52) taken 8 times.
✗ Branch 3 (51→53) not taken.
✓ Branch 4 (54→55) taken 8 times.
✗ Branch 5 (54→56) not taken.
|
8 | if(!min_version.empty() && min_version.back() == ',') min_version.pop_back(); |
| 35 | } | ||
| 36 |
11/18✓ Branch 0 (57→58) taken 16 times.
✓ Branch 2 (58→59) taken 16 times.
✓ Branch 4 (59→60) taken 16 times.
✗ Branch 5 (59→64) not taken.
✓ Branch 6 (61→62) taken 16 times.
✓ Branch 8 (62→63) taken 16 times.
✓ Branch 10 (63→64) taken 8 times.
✓ Branch 11 (63→65) taken 8 times.
✓ Branch 12 (66→67) taken 16 times.
✗ Branch 13 (66→68) not taken.
✓ Branch 14 (68→69) taken 16 times.
✗ Branch 15 (68→70) not taken.
✓ Branch 16 (70→71) taken 8 times.
✓ Branch 17 (70→81) taken 8 times.
✗ Branch 18 (121→122) not taken.
✗ Branch 19 (121→123) not taken.
✗ Branch 20 (125→126) not taken.
✗ Branch 21 (125→127) not taken.
|
16 | if(depValues[i].isSameBegining("<=") || depValues[i].isSameBegining("<")) { |
| 37 |
1/1✓ Branch 0 (72→73) taken 8 times.
|
8 | max_version = depValues[i]; |
| 38 |
3/6✓ Branch 0 (74→75) taken 8 times.
✗ Branch 1 (74→78) not taken.
✗ Branch 2 (76→77) not taken.
✓ Branch 3 (76→78) taken 8 times.
✗ Branch 4 (79→80) not taken.
✓ Branch 5 (79→81) taken 8 times.
|
8 | if(!max_version.empty() && max_version.back() == ',') max_version.pop_back(); |
| 39 | } | ||
| 40 | } | ||
| 41 | }else{ | ||
| 42 | ✗ | name = depStr; | |
| 43 | } | ||
| 44 | // Fill the matching attributes | ||
| 45 |
2/2✓ Branch 0 (86→87) taken 10 times.
✓ Branch 2 (87→88) taken 10 times.
|
10 | config.mapDependencies[name].setName(name); |
| 46 |
2/2✓ Branch 0 (88→89) taken 10 times.
✓ Branch 2 (89→90) taken 10 times.
|
10 | config.mapDependencies[name].setMinVersion(min_version); |
| 47 |
2/2✓ Branch 0 (90→91) taken 10 times.
✓ Branch 2 (91→92) taken 10 times.
|
10 | config.mapDependencies[name].setMaxVersion(max_version); |
| 48 | 10 | } | |
| 49 | 3 | return true; | |
| 50 | } | ||
| 51 | |||
| 52 | ///Parse project members (authors, maintainers, contributors) from TOML data | ||
| 53 | /** @param[out] memberMap : map to fill with parsed members | ||
| 54 | * @param memberDico : TOML dictionary containing the members data | ||
| 55 | * @return true on success, false otherwise | ||
| 56 | */ | ||
| 57 | 9 | bool parseProjectMembers(ProjectMembersMap & memberMap, const DicoValue * memberDico){ | |
| 58 |
3/6✓ Branch 0 (2→3) taken 9 times.
✗ Branch 1 (2→5) not taken.
✗ Branch 2 (4→5) not taken.
✓ Branch 3 (4→6) taken 9 times.
✗ Branch 4 (7→8) not taken.
✓ Branch 5 (7→9) taken 9 times.
|
9 | if(memberDico == NULL || !memberDico->hasVec()){ |
| 59 | ✗ | return false; | |
| 60 | } | ||
| 61 | 9 | const std::vector<DicoValue> & vecMember = memberDico->getVecChild(); | |
| 62 |
2/2✓ Branch 0 (57→11) taken 12 times.
✓ Branch 1 (57→58) taken 9 times.
|
21 | for(size_t iMember = 0; iMember < vecMember.size(); iMember++){ |
| 63 | 12 | const DicoValue & memberData = vecMember[iMember]; | |
| 64 |
1/2✓ Branch 0 (13→14) taken 12 times.
✗ Branch 1 (13→55) not taken.
|
12 | if(memberData.hasMap()){ |
| 65 |
1/1✓ Branch 0 (14→15) taken 12 times.
|
12 | PProjectMembers member; |
| 66 |
4/4✓ Branch 0 (15→16) taken 12 times.
✓ Branch 2 (16→17) taken 12 times.
✓ Branch 4 (17→18) taken 12 times.
✓ Branch 6 (18→19) taken 12 times.
|
12 | member.setLastName(phoenix_get_string(memberData, "lastName", "")); |
| 67 |
4/4✓ Branch 0 (22→23) taken 12 times.
✓ Branch 2 (23→24) taken 12 times.
✓ Branch 4 (24→25) taken 12 times.
✓ Branch 6 (25→26) taken 12 times.
|
12 | member.setFirstName(phoenix_get_string(memberData, "firstName", "")); |
| 68 |
4/4✓ Branch 0 (29→30) taken 12 times.
✓ Branch 2 (30→31) taken 12 times.
✓ Branch 4 (31→32) taken 12 times.
✓ Branch 6 (32→33) taken 12 times.
|
12 | member.setAffiliation(phoenix_get_string(memberData, "affiliation", "")); |
| 69 |
4/4✓ Branch 0 (36→37) taken 12 times.
✓ Branch 2 (37→38) taken 12 times.
✓ Branch 4 (38→39) taken 12 times.
✓ Branch 6 (39→40) taken 12 times.
|
12 | member.setEmail(phoenix_get_string(memberData, "mail", "")); |
| 70 | |||
| 71 | // Use lastName + firstName as key to handle duplicate lastNames | ||
| 72 |
5/5✓ Branch 0 (43→44) taken 12 times.
✓ Branch 2 (44→45) taken 12 times.
✓ Branch 4 (45→46) taken 12 times.
✓ Branch 6 (46→47) taken 12 times.
✓ Branch 8 (47→48) taken 12 times.
|
12 | PString key = member.getLastName() + "_" + member.getFirstName(); |
| 73 |
2/2✓ Branch 0 (50→51) taken 12 times.
✓ Branch 2 (51→52) taken 12 times.
|
12 | memberMap[key] = member; |
| 74 | 12 | } | |
| 75 | } | ||
| 76 | 9 | return true; | |
| 77 | } | ||
| 78 | |||
| 79 | ///Load the project configuration | ||
| 80 | /** @param[out] config : loaded project configuration | ||
| 81 | * @param descriptionFile : description of the full project | ||
| 82 | * @return true on success, false otherwise | ||
| 83 | */ | ||
| 84 | 3 | bool project_generator_loadConfig(ProjectConfig & config, const PPath & descriptionFile){ | |
| 85 |
1/1✓ Branch 0 (2→3) taken 3 times.
|
3 | DicoValue dico; |
| 86 |
2/3✓ Branch 0 (3→4) taken 3 times.
✗ Branch 2 (4→5) not taken.
✓ Branch 3 (4→16) taken 3 times.
|
3 | if(!parser_toml(dico, descriptionFile)){ |
| 87 | ✗ | std::cerr << termRed() << "project_generator_loadConfig : cannot parse config file '"<<descriptionFile<<"'" << termDefault() << std::endl; | |
| 88 | ✗ | return false; | |
| 89 | } | ||
| 90 |
2/2✓ Branch 0 (16→17) taken 3 times.
✓ Branch 2 (17→18) taken 3 times.
|
3 | DicoValue * mapProject = dico.getMap("project"); |
| 91 |
1/2✗ Branch 0 (19→20) not taken.
✓ Branch 1 (19→31) taken 3 times.
|
3 | if(mapProject == NULL){ |
| 92 | ✗ | std::cerr << termRed() << "project_generator_loadConfig : Missing [project] in config file '"<<descriptionFile<<"'" << termDefault() << std::endl; | |
| 93 | ✗ | return false; | |
| 94 | } | ||
| 95 | //TODO : It should be better to tell if there are missing values, but it's late ... | ||
| 96 |
4/4✓ Branch 0 (31→32) taken 3 times.
✓ Branch 2 (32→33) taken 3 times.
✓ Branch 4 (33→34) taken 3 times.
✓ Branch 6 (34→35) taken 3 times.
|
3 | config.name = phoenix_get_string(*mapProject, "name", "MyAwesomeProject"); |
| 97 |
4/4✓ Branch 0 (38→39) taken 3 times.
✓ Branch 2 (39→40) taken 3 times.
✓ Branch 4 (40→41) taken 3 times.
✓ Branch 6 (41→42) taken 3 times.
|
3 | config.url = phoenix_get_string(*mapProject, "url", "need and url"); |
| 98 |
4/4✓ Branch 0 (45→46) taken 3 times.
✓ Branch 2 (46→47) taken 3 times.
✓ Branch 4 (47→48) taken 3 times.
✓ Branch 6 (48→49) taken 3 times.
|
3 | config.version = phoenix_get_string(*mapProject, "version", "0.1.0"); |
| 99 |
4/4✓ Branch 0 (52→53) taken 3 times.
✓ Branch 2 (53→54) taken 3 times.
✓ Branch 4 (54→55) taken 3 times.
✓ Branch 6 (55→56) taken 3 times.
|
3 | config.description = phoenix_get_string(*mapProject, "description", "A very important project"); |
| 100 |
4/4✓ Branch 0 (59→60) taken 3 times.
✓ Branch 2 (60→61) taken 3 times.
✓ Branch 4 (61→62) taken 3 times.
✓ Branch 6 (62→63) taken 3 times.
|
3 | config.mainBranch = phoenix_get_string(*mapProject, "main_branch", "main"); |
| 101 |
4/4✓ Branch 0 (66→67) taken 3 times.
✓ Branch 2 (67→68) taken 3 times.
✓ Branch 4 (68→69) taken 3 times.
✓ Branch 6 (69→70) taken 3 times.
|
3 | config.runnerTag = phoenix_get_string(*mapProject, "runner_tag", ""); //Could be MUST_big_runner |
| 102 |
4/4✓ Branch 0 (73→74) taken 3 times.
✓ Branch 2 (74→75) taken 3 times.
✓ Branch 4 (75→76) taken 3 times.
✓ Branch 6 (76→77) taken 3 times.
|
3 | config.ciToolkitVersion = phoenix_get_string(*mapProject, "ci_toolkit_version", "3.0.4"); //Default version if not specified |
| 103 |
4/4✓ Branch 0 (80→81) taken 3 times.
✓ Branch 2 (81→82) taken 3 times.
✓ Branch 4 (82→83) taken 3 times.
✓ Branch 6 (83→84) taken 3 times.
|
3 | config.ciToolkitUrl = phoenix_get_string(*mapProject, "ci_toolkit_url", "https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/citoolkit/phoenixcitoolkitcpp/phoenix-workflow-cpp"); |
| 104 | |||
| 105 | //Keywords | ||
| 106 |
3/4✓ Branch 0 (87→88) taken 3 times.
✓ Branch 2 (88→89) taken 3 times.
✓ Branch 4 (90→91) taken 3 times.
✗ Branch 5 (90→109) not taken.
|
3 | if(mapProject->isKeyExist("keywords")){ |
| 107 |
2/2✓ Branch 0 (91→92) taken 3 times.
✓ Branch 2 (92→93) taken 3 times.
|
3 | const DicoValue * keywordDico = mapProject->getMap("keywords"); |
| 108 |
4/7✓ Branch 0 (94→95) taken 3 times.
✗ Branch 1 (94→98) not taken.
✓ Branch 2 (95→96) taken 3 times.
✓ Branch 4 (96→97) taken 3 times.
✗ Branch 5 (96→98) not taken.
✓ Branch 6 (99→100) taken 3 times.
✗ Branch 7 (99→109) not taken.
|
3 | if(keywordDico != NULL && keywordDico->hasVec()){ |
| 109 |
1/1✓ Branch 0 (100→101) taken 3 times.
|
3 | const std::vector<DicoValue> & vecKeyword = keywordDico->getVecChild(); |
| 110 |
2/2✓ Branch 0 (108→102) taken 15 times.
✓ Branch 1 (108→109) taken 3 times.
|
18 | for(size_t iKeyword = 0; iKeyword < vecKeyword.size(); iKeyword++){ |
| 111 |
2/2✓ Branch 0 (103→104) taken 15 times.
✓ Branch 2 (104→105) taken 15 times.
|
15 | config.keywordList.push_back(vecKeyword[iKeyword].getString());; |
| 112 | } | ||
| 113 | } | ||
| 114 | } | ||
| 115 | //Authors | ||
| 116 |
3/4✓ Branch 0 (109→110) taken 3 times.
✓ Branch 2 (110→111) taken 3 times.
✓ Branch 4 (112→113) taken 3 times.
✗ Branch 5 (112→117) not taken.
|
3 | if(mapProject->isKeyExist("authors")){ |
| 117 |
2/2✓ Branch 0 (113→114) taken 3 times.
✓ Branch 2 (114→115) taken 3 times.
|
3 | const DicoValue * authorDico = mapProject->getMap("authors"); |
| 118 |
1/1✓ Branch 0 (116→117) taken 3 times.
|
3 | parseProjectMembers(config.authorMap, authorDico); |
| 119 | } | ||
| 120 | //Maintainers | ||
| 121 |
3/4✓ Branch 0 (117→118) taken 3 times.
✓ Branch 2 (118→119) taken 3 times.
✓ Branch 4 (120→121) taken 3 times.
✗ Branch 5 (120→125) not taken.
|
3 | if(mapProject->isKeyExist("maintainers")){ |
| 122 |
2/2✓ Branch 0 (121→122) taken 3 times.
✓ Branch 2 (122→123) taken 3 times.
|
3 | const DicoValue * maintainerDico = mapProject->getMap("maintainers"); |
| 123 |
1/1✓ Branch 0 (124→125) taken 3 times.
|
3 | parseProjectMembers(config.maintainerMap, maintainerDico); |
| 124 | } | ||
| 125 | //Contributors | ||
| 126 |
3/4✓ Branch 0 (125→126) taken 3 times.
✓ Branch 2 (126→127) taken 3 times.
✓ Branch 4 (128→129) taken 3 times.
✗ Branch 5 (128→133) not taken.
|
3 | if(mapProject->isKeyExist("contributors")){ |
| 127 |
2/2✓ Branch 0 (129→130) taken 3 times.
✓ Branch 2 (130→131) taken 3 times.
|
3 | const DicoValue * contributorDico = mapProject->getMap("contributors"); |
| 128 |
1/1✓ Branch 0 (132→133) taken 3 times.
|
3 | parseProjectMembers(config.contributorMap, contributorDico); |
| 129 | } | ||
| 130 | //Dependencies | ||
| 131 |
3/4✓ Branch 0 (133→134) taken 3 times.
✓ Branch 2 (134→135) taken 3 times.
✓ Branch 4 (136→137) taken 3 times.
✗ Branch 5 (136→175) not taken.
|
3 | if(mapProject->isKeyExist("dependencies")){ |
| 132 |
2/2✓ Branch 0 (137→138) taken 3 times.
✓ Branch 2 (138→139) taken 3 times.
|
3 | const DicoValue * depDico = mapProject->getMap("dependencies"); |
| 133 |
4/7✓ Branch 0 (140→141) taken 3 times.
✗ Branch 1 (140→144) not taken.
✓ Branch 2 (141→142) taken 3 times.
✓ Branch 4 (142→143) taken 3 times.
✗ Branch 5 (142→144) not taken.
✓ Branch 6 (145→146) taken 3 times.
✗ Branch 7 (145→175) not taken.
|
3 | if(depDico != NULL && depDico->hasVec()){ |
| 134 |
1/1✓ Branch 0 (146→147) taken 3 times.
|
3 | const std::vector<DicoValue> & vecDep = depDico->getVecChild(); |
| 135 | 3 | std::vector<PString> depList; | |
| 136 |
2/2✓ Branch 0 (155→149) taken 10 times.
✓ Branch 1 (155→156) taken 3 times.
|
13 | for(size_t iDep = 0; iDep < vecDep.size(); iDep++){ |
| 137 |
2/2✓ Branch 0 (150→151) taken 10 times.
✓ Branch 2 (151→152) taken 10 times.
|
10 | depList.push_back(vecDep[iDep].getString()); |
| 138 | } | ||
| 139 |
2/3✓ Branch 0 (156→157) taken 3 times.
✗ Branch 2 (157→158) not taken.
✓ Branch 3 (157→169) taken 3 times.
|
3 | if(!project_generator_split_dependencies(config, depList)){ |
| 140 | ✗ | std::cerr << termRed() << "project_generator_loadConfig : cannot parse dependencies in config file '"<<descriptionFile<<"'" << termDefault() << std::endl; | |
| 141 | ✗ | return false; | |
| 142 | } | ||
| 143 | 3 | } | |
| 144 | } | ||
| 145 | 3 | return true; | |
| 146 | 3 | } | |
| 147 | |||
| 148 | |||
| 149 | ///Generate an empty package info file skeleton | ||
| 150 | /** @param[out] outFileName : output file name | ||
| 151 | * @param name : name of the package | ||
| 152 | * @param minVersion : minimum version of the package | ||
| 153 | * @param maxVersion : maximum version of the package | ||
| 154 | */ | ||
| 155 | 1 | bool generate_empty_config(PPath & outFileName, const PString & name, PString& minVersion, PString& maxVersion){ | |
| 156 |
1/1✓ Branch 0 (2→3) taken 1 times.
|
1 | PString body; |
| 157 |
1/1✓ Branch 0 (3→4) taken 1 times.
|
1 | body += "# To fill the package info use the description below, then remove the commented lines.\n"; |
| 158 |
1/1✓ Branch 0 (4→5) taken 1 times.
|
1 | body += "[[Package]]\n"; |
| 159 |
1/1✓ Branch 0 (5→6) taken 1 times.
|
1 | body += "# This is the name of your package (eg on your git repository)\n"; |
| 160 |
3/3✓ Branch 0 (6→7) taken 1 times.
✓ Branch 2 (7→8) taken 1 times.
✓ Branch 4 (8→9) taken 1 times.
|
1 | body += "name = \"" + name + "\"\n"; |
| 161 |
1/1✓ Branch 0 (11→12) taken 1 times.
|
1 | body += "# # This is the name of your package for the pixi.toml. You can find the name of the pixi package by searching it on prefix.dev \n"; |
| 162 |
1/1✓ Branch 0 (12→13) taken 1 times.
|
1 | body += "pixi_name = \"\"\n"; |
| 163 |
1/1✓ Branch 0 (13→14) taken 1 times.
|
1 | body += "# If your package provides a CMake configuration file (find File), this should be the value used in find_package().\n"; |
| 164 |
1/1✓ Branch 0 (14→15) taken 1 times.
|
1 | body += "cmake_find = \"\"\n"; |
| 165 |
1/1✓ Branch 0 (15→16) taken 1 times.
|
1 | body += "# If your package provides a CMake configuration library, this should be the name of the main library target provided by the package.\n"; |
| 166 |
1/1✓ Branch 0 (16→17) taken 1 times.
|
1 | body += "cmake_lib = \"\"\n"; |
| 167 |
1/1✓ Branch 0 (17→18) taken 1 times.
|
1 | body += "#This is the URL of your package repository if you want to use the pull_extra_module feature of PhoenixCMake (only for Phoenix packages)\n"; |
| 168 |
1/1✓ Branch 0 (18→19) taken 1 times.
|
1 | body += "url = \"\"\n\n"; |
| 169 |
1/1✓ Branch 0 (19→20) taken 1 times.
|
2 | return outFileName.saveFileContent(body); |
| 170 | 1 | } | |
| 171 | |||
| 172 | ///Check the package file | ||
| 173 | /** @param fileName : configuration file | ||
| 174 | * @param name : name of the project to search | ||
| 175 | * @param packageDir : directory where package configuration are stored | ||
| 176 | * @param[out] pkgAttr : PPackageAttribute to be set | ||
| 177 | * @return true if the package name has been found, false otherwise | ||
| 178 | */ | ||
| 179 | 39 | bool check_package_file(const PPath & fileName, const PString & name, const PPath & packageDir, PPackageAttribute & pkgAttr){ | |
| 180 | 39 | bool found = false; | |
| 181 |
3/4✓ Branch 0 (2→3) taken 39 times.
✓ Branch 2 (3→4) taken 39 times.
✗ Branch 4 (5→6) not taken.
✓ Branch 5 (5→7) taken 39 times.
|
39 | if(fileName.getExtension() != "toml"){ |
| 182 | ✗ | return found; | |
| 183 | } | ||
| 184 |
1/1✓ Branch 0 (7→8) taken 39 times.
|
39 | DicoValue dico; |
| 185 |
1/1✓ Branch 0 (8→9) taken 39 times.
|
39 | PPath tomlFile = packageDir / fileName; |
| 186 |
2/3✓ Branch 0 (9→10) taken 39 times.
✗ Branch 2 (10→11) not taken.
✓ Branch 3 (10→12) taken 39 times.
|
39 | if(!parser_toml(dico, tomlFile)){ |
| 187 | ✗ | return found; | |
| 188 | } | ||
| 189 |
2/2✓ Branch 0 (12→13) taken 39 times.
✓ Branch 2 (13→14) taken 39 times.
|
39 | const DicoValue* mapPkg = dico.getMap("Package"); |
| 190 |
1/1✓ Branch 0 (15→16) taken 39 times.
|
39 | const std::vector<DicoValue> & vecChild = mapPkg->getVecChild(); |
| 191 |
6/6✓ Branch 0 (83→84) taken 312 times.
✓ Branch 1 (83→86) taken 30 times.
✓ Branch 2 (84→85) taken 303 times.
✓ Branch 3 (84→86) taken 9 times.
✓ Branch 4 (87→17) taken 303 times.
✓ Branch 5 (87→88) taken 39 times.
|
342 | for(size_t iChild = 0; iChild < vecChild.size() && !found; ++iChild){ |
| 192 | 303 | const DicoValue & pkgBlock = vecChild[iChild]; | |
| 193 |
3/3✓ Branch 0 (18→19) taken 303 times.
✓ Branch 2 (19→20) taken 303 times.
✓ Branch 4 (20→21) taken 303 times.
|
303 | PString tomlName = phoenix_get_string(pkgBlock, "name", ""); |
| 194 |
2/2✓ Branch 0 (24→25) taken 9 times.
✓ Branch 1 (24→80) taken 294 times.
|
303 | if(tomlName == name){ |
| 195 |
4/4✓ Branch 0 (25→26) taken 9 times.
✓ Branch 2 (26→27) taken 9 times.
✓ Branch 4 (27→28) taken 9 times.
✓ Branch 6 (28→29) taken 9 times.
|
9 | pkgAttr.setUrl(phoenix_get_string(pkgBlock, "url", "")); |
| 196 |
4/4✓ Branch 0 (32→33) taken 9 times.
✓ Branch 2 (33→34) taken 9 times.
✓ Branch 4 (34→35) taken 9 times.
✓ Branch 6 (35→36) taken 9 times.
|
9 | pkgAttr.setPixiName(phoenix_get_string(pkgBlock, "pixi_name", "")); |
| 197 |
4/4✓ Branch 0 (39→40) taken 9 times.
✓ Branch 2 (40→41) taken 9 times.
✓ Branch 4 (41→42) taken 9 times.
✓ Branch 6 (42→43) taken 9 times.
|
9 | pkgAttr.setCmakeFind(phoenix_get_string(pkgBlock, "cmake_find", "")); |
| 198 |
4/4✓ Branch 0 (46→47) taken 9 times.
✓ Branch 2 (47→48) taken 9 times.
✓ Branch 4 (48→49) taken 9 times.
✓ Branch 6 (49→50) taken 9 times.
|
9 | pkgAttr.setCmakeLib(phoenix_get_string(pkgBlock, "cmake_lib", "")); |
| 199 |
8/18✓ Branch 0 (53→54) taken 9 times.
✓ Branch 2 (54→55) taken 9 times.
✓ Branch 4 (55→56) taken 1 times.
✓ Branch 5 (55→65) taken 8 times.
✓ Branch 6 (56→57) taken 1 times.
✓ Branch 8 (57→58) taken 1 times.
✗ Branch 10 (58→59) not taken.
✓ Branch 11 (58→65) taken 1 times.
✗ Branch 12 (59→60) not taken.
✗ Branch 14 (60→61) not taken.
✗ Branch 16 (61→62) not taken.
✗ Branch 17 (61→65) not taken.
✗ Branch 18 (62→63) not taken.
✗ Branch 20 (63→64) not taken.
✗ Branch 22 (64→65) not taken.
✗ Branch 23 (64→66) not taken.
✓ Branch 24 (67→68) taken 9 times.
✗ Branch 25 (67→69) not taken.
|
9 | if(pkgAttr.getUrl() != "" || pkgAttr.getPixiName() != "" || pkgAttr.getCmakeFind() != "" || pkgAttr.getCmakeLib() != ""){ |
| 200 | 9 | found = true; | |
| 201 | }else{ | ||
| 202 | ✗ | std::cerr << termRed() << "check_package_file : incomplete package file '"<<tomlFile<<"'" << termDefault() << std::endl; | |
| 203 | } | ||
| 204 | } | ||
| 205 | 303 | } | |
| 206 | 39 | return found; | |
| 207 | 39 | } | |
| 208 | |||
| 209 | ///Search the package in the package directory | ||
| 210 | /** @param packageFileNames : list of package configuration files | ||
| 211 | * @param name : name of the project to search | ||
| 212 | * @param packageDir : directory where package configuration are stored | ||
| 213 | * @param[out] pkgAttr : PPackageAttribute to be set | ||
| 214 | * @return true if the package name has been found, false otherwise | ||
| 215 | */ | ||
| 216 | 10 | bool is_package_in_dir(std::vector<PPath> & packageFileNames, const PString & name, const PPath & packageDir, PPackageAttribute & pkgAttr){ | |
| 217 |
2/2✓ Branch 0 (22→3) taken 39 times.
✓ Branch 1 (22→23) taken 1 times.
|
40 | for(size_t iFile = 0; iFile < packageFileNames.size(); ++iFile){ |
| 218 |
2/2✓ Branch 0 (5→6) taken 9 times.
✓ Branch 1 (5→20) taken 30 times.
|
39 | if(check_package_file(packageFileNames[iFile], name, packageDir, pkgAttr)){ |
| 219 |
10/10✓ Branch 0 (6→7) taken 9 times.
✓ Branch 2 (7→8) taken 9 times.
✓ Branch 4 (8→9) taken 9 times.
✓ Branch 6 (9→10) taken 9 times.
✓ Branch 8 (10→11) taken 9 times.
✓ Branch 10 (12→13) taken 9 times.
✓ Branch 12 (13→14) taken 9 times.
✓ Branch 14 (14→15) taken 9 times.
✓ Branch 16 (15→16) taken 9 times.
✓ Branch 18 (16→17) taken 9 times.
|
9 | std::cout << termGreen() << "Found package '" << name << "' in file '" << packageFileNames[iFile] << "'." << termDefault() << std::endl; |
| 220 | 9 | return true; | |
| 221 | } | ||
| 222 | } | ||
| 223 | 1 | return false; | |
| 224 | } | ||
| 225 | |||
| 226 | ///Generate an empty package info file skeleton and notify the user | ||
| 227 | /** @param[out] tomlFile : output file name | ||
| 228 | * @param name : name of the package | ||
| 229 | * @param pkgAttr : PPackageAttribute containing version info | ||
| 230 | */ | ||
| 231 | 1 | void is_generate_empty_config_ok(PPath & tomlFile, const PString & name, PPackageAttribute & pkgAttr){ | |
| 232 |
1/2✗ Branch 0 (5→6) not taken.
✓ Branch 1 (5→17) taken 1 times.
|
1 | if(!generate_empty_config(tomlFile, name, pkgAttr.getMinVersion(), pkgAttr.getMaxVersion())){ |
| 233 | ✗ | std::cerr << termRed() << "project_generator_loadPackageInfo : cannot generate empty config file for package '"<<name<<"'" << termDefault() << std::endl; | |
| 234 | } | ||
| 235 | else{ | ||
| 236 |
10/10✓ Branch 0 (17→18) taken 1 times.
✓ Branch 2 (18→19) taken 1 times.
✓ Branch 4 (19→20) taken 1 times.
✓ Branch 6 (20→21) taken 1 times.
✓ Branch 8 (21→22) taken 1 times.
✓ Branch 10 (22→23) taken 1 times.
✓ Branch 12 (23→24) taken 1 times.
✓ Branch 14 (24→25) taken 1 times.
✓ Branch 16 (25→26) taken 1 times.
✓ Branch 18 (26→27) taken 1 times.
|
1 | std::cerr << termYellow() << "Package '" << name << "' does not exist in the configuration. A skeleton file has been created at '" << tomlFile << "'. Please complete it manually." << termDefault() << std::endl; |
| 237 | } | ||
| 238 | 1 | } | |
| 239 | |||
| 240 | ///This function should load the package info file from share/PhoenixGenerator/Packages and retrieve the infos in the datastructure | ||
| 241 | /** @param[out] config : project configuration to fill | ||
| 242 | * @return true on success, false otherwise | ||
| 243 | */ | ||
| 244 | 3 | bool project_generator_loadPackageInfo(ProjectConfig & config){ | |
| 245 | // 1. Get all files in "share/PhoenixGenerator/Packages" | ||
| 246 |
11/11✓ Branch 0 (2→3) taken 3 times.
✓ Branch 2 (3→4) taken 3 times.
✓ Branch 4 (4→5) taken 3 times.
✓ Branch 6 (5→6) taken 3 times.
✓ Branch 8 (6→7) taken 3 times.
✓ Branch 10 (7→8) taken 3 times.
✓ Branch 12 (8→9) taken 3 times.
✓ Branch 14 (9→10) taken 3 times.
✓ Branch 16 (10→11) taken 3 times.
✓ Branch 18 (11→12) taken 3 times.
✓ Branch 20 (12→13) taken 3 times.
|
3 | PPath packageDir = PPath(SYSTEM_INSTALL_DIR) / PPath("share") / PPath("PhoenixGenerator") / PPath("Packages"); |
| 247 |
4/4✓ Branch 0 (23→24) taken 3 times.
✓ Branch 2 (24→25) taken 3 times.
✓ Branch 4 (25→26) taken 3 times.
✓ Branch 6 (26→27) taken 3 times.
|
3 | std::cout << "Loading package info from directory '" << packageDir << "'." << std::endl; |
| 248 |
1/1✓ Branch 0 (27→28) taken 3 times.
|
3 | PVecPath packageFileNames = packageDir.getAllFileInDir(); |
| 249 | 3 | size_t packageNotFound = 0; | |
| 250 | |||
| 251 | // 2. Search in toml files in PackageDir for each package, and fill other attributes if found | ||
| 252 |
2/2✓ Branch 0 (68→29) taken 10 times.
✓ Branch 1 (68→69) taken 3 times.
|
13 | for(PackageMap::iterator it = config.mapDependencies.begin(); it != config.mapDependencies.end(); ++it){ |
| 253 | 10 | const PString & name = it->first; | |
| 254 | 10 | PPackageAttribute & pkgAttr = it->second; | |
| 255 | |||
| 256 |
3/3✓ Branch 0 (31→32) taken 10 times.
✓ Branch 2 (32→33) taken 1 times.
✓ Branch 3 (32→65) taken 9 times.
|
10 | if(!is_package_in_dir(packageFileNames, name, packageDir, pkgAttr)){ |
| 257 |
4/4✓ Branch 0 (33→34) taken 1 times.
✓ Branch 2 (34→35) taken 1 times.
✓ Branch 4 (35→36) taken 1 times.
✓ Branch 6 (36→37) taken 1 times.
|
1 | PPath localPackageDir = PPath::getCurrentDirectory() / PPath("Packages"); |
| 258 |
3/3✓ Branch 0 (40→41) taken 1 times.
✓ Branch 2 (41→42) taken 1 times.
✓ Branch 4 (42→43) taken 1 times.
|
1 | std::cout << "saving file in local dir: " << localPackageDir << std::endl; |
| 259 |
4/4✓ Branch 0 (43→44) taken 1 times.
✓ Branch 2 (44→45) taken 1 times.
✓ Branch 4 (45→46) taken 1 times.
✓ Branch 6 (46→47) taken 1 times.
|
1 | PPath tomlFile = localPackageDir / PPath(name + ".toml"); |
| 260 |
2/3✓ Branch 0 (50→51) taken 1 times.
✗ Branch 2 (51→52) not taken.
✓ Branch 3 (51→59) taken 1 times.
|
1 | if(localPackageDir.isDirectoryExist()){ |
| 261 | ✗ | PVecPath localPackageFileNames = localPackageDir.getAllFileInDir(); | |
| 262 | ✗ | if(!is_package_in_dir(localPackageFileNames, name, localPackageDir, pkgAttr)){ | |
| 263 | ✗ | is_generate_empty_config_ok(tomlFile, name, pkgAttr); | |
| 264 | ✗ | packageNotFound++; | |
| 265 | } | ||
| 266 | ✗ | } | |
| 267 | //If the folder does not exists it means that the package we are looking for is unknown, so we create an empty config file inside the new created Packages/ directory | ||
| 268 | else{ | ||
| 269 |
1/1✓ Branch 0 (59→60) taken 1 times.
|
1 | localPackageDir.createDirectory(); |
| 270 |
1/1✓ Branch 0 (60→61) taken 1 times.
|
1 | is_generate_empty_config_ok(tomlFile, name, pkgAttr); |
| 271 | 1 | packageNotFound++; | |
| 272 | } | ||
| 273 | 1 | } | |
| 274 | } | ||
| 275 |
2/2✓ Branch 0 (69→70) taken 1 times.
✓ Branch 1 (69→80) taken 2 times.
|
3 | if(packageNotFound != 0){ |
| 276 |
7/7✓ Branch 0 (70→71) taken 1 times.
✓ Branch 2 (71→72) taken 1 times.
✓ Branch 4 (72→73) taken 1 times.
✓ Branch 6 (73→74) taken 1 times.
✓ Branch 8 (74→75) taken 1 times.
✓ Branch 10 (75→76) taken 1 times.
✓ Branch 12 (76→77) taken 1 times.
|
1 | std::cout << termRed() << packageNotFound << " package(s) not found in the package directory." << termDefault() << std::endl; |
| 277 | } | ||
| 278 | 3 | return packageNotFound == 0; | |
| 279 | 3 | } | |
| 280 | |||
| 281 | |||
| 282 |