PhoenixGenerator  2.0.4
Set of tools to generate code
Loading...
Searching...
No Matches
project_generator_load.h File Reference
#include "PPath.h"
#include "PPackageAttribute.h"
#include "PProjectMembers.h"
+ Include dependency graph for project_generator_load.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ProjectConfig
 Configuration of the project. More...
 

Typedefs

typedef std::map< PString, PPackageAttributePackageMap
 
typedef std::map< PString, PProjectMembersProjectMembersMap
 

Functions

bool project_generator_loadConfig (ProjectConfig &config, const PPath &descriptionFile)
 Load the project configuration.
 
bool project_generator_loadPackageInfo (ProjectConfig &config)
 This function should load the package info file from share/PhoenixGenerator/Packages and retrieve the infos in the datastructure.
 

Typedef Documentation

◆ PackageMap

typedef std::map<PString, PPackageAttribute> PackageMap

Definition at line 14 of file project_generator_load.h.

◆ ProjectMembersMap

typedef std::map<PString, PProjectMembers> ProjectMembersMap

Definition at line 15 of file project_generator_load.h.

Function Documentation

◆ project_generator_loadConfig()

bool project_generator_loadConfig ( ProjectConfig & config,
const PPath & descriptionFile )

Load the project configuration.

Parameters
[out]config: loaded project configuration
descriptionFile: description of the full project
Returns
true on success, false otherwise

Definition at line 84 of file project_generator_load.cpp.

84 {
85 DicoValue dico;
86 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 DicoValue * mapProject = dico.getMap("project");
91 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 config.name = phoenix_get_string(*mapProject, "name", "MyAwesomeProject");
97 config.url = phoenix_get_string(*mapProject, "url", "need and url");
98 config.version = phoenix_get_string(*mapProject, "version", "0.1.0");
99 config.description = phoenix_get_string(*mapProject, "description", "A very important project");
100 config.mainBranch = phoenix_get_string(*mapProject, "main_branch", "main");
101 config.runnerTag = phoenix_get_string(*mapProject, "runner_tag", ""); //Could be MUST_big_runner
102 config.ciToolkitVersion = phoenix_get_string(*mapProject, "ci_toolkit_version", "3.0.4"); //Default version if not specified
103 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 if(mapProject->isKeyExist("keywords")){
107 const DicoValue * keywordDico = mapProject->getMap("keywords");
108 if(keywordDico != NULL && keywordDico->hasVec()){
109 const std::vector<DicoValue> & vecKeyword = keywordDico->getVecChild();
110 for(size_t iKeyword = 0; iKeyword < vecKeyword.size(); iKeyword++){
111 config.keywordList.push_back(vecKeyword[iKeyword].getString());;
112 }
113 }
114 }
115 //Authors
116 if(mapProject->isKeyExist("authors")){
117 const DicoValue * authorDico = mapProject->getMap("authors");
118 parseProjectMembers(config.authorMap, authorDico);
119 }
120 //Maintainers
121 if(mapProject->isKeyExist("maintainers")){
122 const DicoValue * maintainerDico = mapProject->getMap("maintainers");
123 parseProjectMembers(config.maintainerMap, maintainerDico);
124 }
125 //Contributors
126 if(mapProject->isKeyExist("contributors")){
127 const DicoValue * contributorDico = mapProject->getMap("contributors");
128 parseProjectMembers(config.contributorMap, contributorDico);
129 }
130 //Dependencies
131 if(mapProject->isKeyExist("dependencies")){
132 const DicoValue * depDico = mapProject->getMap("dependencies");
133 if(depDico != NULL && depDico->hasVec()){
134 const std::vector<DicoValue> & vecDep = depDico->getVecChild();
135 std::vector<PString> depList;
136 for(size_t iDep = 0; iDep < vecDep.size(); iDep++){
137 depList.push_back(vecDep[iDep].getString());
138 }
139 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 }
144 }
145 return true;
146}
bool project_generator_split_dependencies(ProjectConfig &config, std::vector< PString > &vecDependencies)
Split dependencies strings into name, min_version, max_version and fill the map of dependencies.
bool parseProjectMembers(ProjectMembersMap &memberMap, const DicoValue *memberDico)
Parse project members (authors, maintainers, contributors) from TOML data.
PString description
Description of the project.
ProjectMembersMap contributorMap
Map of the contributors of the project.
PString name
Name of the project.
ProjectMembersMap authorMap
Map of authors of the project.
PString runnerTag
Specific runner tag if needed (could be MUST_big_runner)
PString ciToolkitUrl
CI toolkit url.
PString ciToolkitVersion
Version of the Phoenix CI toolkit component (optional, defaults to 3.0.4)
PString url
Project url.
PString mainBranch
Main branch of hte project.
PString version
Project version.
ProjectMembersMap maintainerMap
Map of maintainers of the project.
std::vector< PString > keywordList
List of keywords linked to the project.

References ProjectConfig::authorMap, ProjectConfig::ciToolkitUrl, ProjectConfig::ciToolkitVersion, ProjectConfig::contributorMap, ProjectConfig::description, ProjectConfig::keywordList, ProjectConfig::mainBranch, ProjectConfig::maintainerMap, ProjectConfig::name, parseProjectMembers(), project_generator_split_dependencies(), ProjectConfig::runnerTag, ProjectConfig::url, and ProjectConfig::version.

Referenced by simple_project_generator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ project_generator_loadPackageInfo()

bool project_generator_loadPackageInfo ( ProjectConfig & config)

This function should load the package info file from share/PhoenixGenerator/Packages and retrieve the infos in the datastructure.

Parameters
[out]config: project configuration to fill
Returns
true on success, false otherwise

Definition at line 244 of file project_generator_load.cpp.

244 {
245 // 1. Get all files in "share/PhoenixGenerator/Packages"
246 PPath packageDir = PPath(SYSTEM_INSTALL_DIR) / PPath("share") / PPath("PhoenixGenerator") / PPath("Packages");
247 std::cout << "Loading package info from directory '" << packageDir << "'." << std::endl;
248 PVecPath packageFileNames = packageDir.getAllFileInDir();
249 size_t packageNotFound = 0;
250
251 // 2. Search in toml files in PackageDir for each package, and fill other attributes if found
252 for(PackageMap::iterator it = config.mapDependencies.begin(); it != config.mapDependencies.end(); ++it){
253 const PString & name = it->first;
254 PPackageAttribute & pkgAttr = it->second;
255
256 if(!is_package_in_dir(packageFileNames, name, packageDir, pkgAttr)){
257 PPath localPackageDir = PPath::getCurrentDirectory() / PPath("Packages");
258 std::cout << "saving file in local dir: " << localPackageDir << std::endl;
259 PPath tomlFile = localPackageDir / PPath(name + ".toml");
260 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 localPackageDir.createDirectory();
270 is_generate_empty_config_ok(tomlFile, name, pkgAttr);
271 packageNotFound++;
272 }
273 }
274 }
275 if(packageNotFound != 0){
276 std::cout << termRed() << packageNotFound << " package(s) not found in the package directory." << termDefault() << std::endl;
277 }
278 return packageNotFound == 0;
279}
Describes a package attributes.
bool is_package_in_dir(std::vector< PPath > &packageFileNames, const PString &name, const PPath &packageDir, PPackageAttribute &pkgAttr)
Search the package in the package directory.
void is_generate_empty_config_ok(PPath &tomlFile, const PString &name, PPackageAttribute &pkgAttr)
Generate an empty package info file skeleton and notify the user.
PackageMap mapDependencies
Map of all dependencies of the project with structure PPackageAttribute values.

References is_generate_empty_config_ok(), is_package_in_dir(), and ProjectConfig::mapDependencies.

Referenced by simple_project_generator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: