PhoenixGenerator  3.4.0
Generate code from template files and projects in C++, Rust, Python and wrapped C++ to Python
Loading...
Searching...
No Matches
simple_project_generator.cpp File Reference
Include dependency graph for simple_project_generator.cpp:

Go to the source code of this file.

Functions

PMapString generateAllReplacementData (const ProjectConfig &projectConfig, const GeneratorMode &mode, const PVecPath &vecClassConfigFile)
 Generate all replacement data for project generation.
PString generateAuthorListPixi (const ProjectConfig &projectConfig)
 Generate author list for Pixi.
PString generateCmakeFindBody (const ProjectConfig &projectConfig)
 Generate CMake find_package commands for non-Phoenix dependencies.
bool generateCppClassesFull (const ProjectParam &projectParam)
 Generate C++ classes with all standard traits.
PString generateMarkdownDepList (const ProjectConfig &projectConfig)
 Generate markdown list of Phoenix dependencies.
bool generateNanobindClassesFull (const ProjectParam &projectParam)
 Generate nanobind wrapper classes.
PString generateNanobindCmakeSources (const ProjectConfig &projectConfig, const PVecPath &vecClassConfigFile, const GeneratorMode &mode)
 Generate the nanobind cmake sources list.
PString generatePhoenixFindModule (const ProjectConfig &projectConfig)
 Generate Phoenix find module list.
PString generatePhoenixGlobalDep (const ProjectConfig &projectConfig)
 Generate Phoenix global dependencies variable.
PString generatePhoenixPullExtraModule (const ProjectConfig &projectConfig)
 Generate Phoenix pull_extra_module commands.
PString generatePixiBody (const ProjectConfig &projectConfig)
 Generate Pixi dependencies.
PMapString generateReplacementMap (const ProjectConfig &projectConfig, const GeneratorMode &mode, const PString &cmakeFindBody, const PString &phoenixPullExtraModule, const PString &phoenixFindModule, const PString &phoenixGlobalDep, const PString &targetLinkBody, const PString &pixiBody, const PString &markdownDepList, const PString &authorListPixi, const PString &nanobindCMakeSources, const PString &rustModuleDeclarations)
 Generate the replacement map for placeholders.
bool generateRustClassesFull (const ProjectParam &projectParam)
 Generate rust classes.
PString generateRustModuleDeclarations (const PVecPath &vecClassConfigFile)
 Generate the Rust module declarations to be written into lib.rs.
PString generateTargetLinkBody (const ProjectConfig &projectConfig)
 Generate target_link_libraries command.
bool generateWrapperClassesFull (const ProjectParam &projectParam)
 Generate wrapper classes.
bool isPhoenixDependency (const PString &packageName)
 Check if a package is a Phoenix dependency.
bool simple_project_generate_source (const ProjectParam &projectParam)
 Save generated sources of project.
bool simple_project_generator (const PPath &descriptionFile, const PVecPath &vecClassConfigFile, const PString &projectType, const GeneratorMode &mode)
 Create a simple project from a configuration.
bool simple_project_load_config (ProjectParam &param, const PPath &pdataDir, const PVecPath &vecClassConfigFile)
 Load configuration pdata of generated sources.
ProjectParam stripNanobindUnsupportedType (const ProjectParam &projectParam)
 Create a ProjectParam with PString and PPath converted into std::string.

Function Documentation

◆ generateAllReplacementData()

PMapString generateAllReplacementData ( const ProjectConfig & projectConfig,
const GeneratorMode & mode,
const PVecPath & vecClassConfigFile )

Generate all replacement data for project generation.

Parameters
projectConfig: project configuration
Returns
replacement map for placeholders

Definition at line 302 of file simple_project_generator.cpp.

302 {
303 // Generate various bodies using dedicated functions
304 PString cmakeFindBody = generateCmakeFindBody(projectConfig);
305 PString phoenixPullExtraModule = generatePhoenixPullExtraModule(projectConfig);
306 PString phoenixFindModule = generatePhoenixFindModule(projectConfig);
307 PString phoenixGlobalDep = generatePhoenixGlobalDep(projectConfig);
308 PString targetLinkBody = generateTargetLinkBody(projectConfig);
309 PString pixiBody = generatePixiBody(projectConfig);
310 PString markdownDepList = generateMarkdownDepList(projectConfig);
311 PString authorListPixi = generateAuthorListPixi(projectConfig);
312 PString nanobindCMakeSources;
314 nanobindCMakeSources = generateNanobindCmakeSources(projectConfig, vecClassConfigFile, mode);
315 }
316 PString rustModuleDeclarations;
317 if(mode.type == ProjectType::RUST){
318 rustModuleDeclarations = generateRustModuleDeclarations(vecClassConfigFile);
319 }
320
321 time_t timestamp;
322 PString dateStr = ctime(&(timestamp = time(nullptr)));
323 dateStr = dateStr.eraseLastChar("\n"); // Remove the trailing \n
324
325 // Generate the replacement map
326 return generateReplacementMap(projectConfig, mode, cmakeFindBody, phoenixPullExtraModule,
327 phoenixFindModule, phoenixGlobalDep, targetLinkBody,
328 pixiBody, markdownDepList, authorListPixi, nanobindCMakeSources, rustModuleDeclarations);
329}
PString generateAuthorListPixi(const ProjectConfig &projectConfig)
Generate author list for Pixi.
PString generateCmakeFindBody(const ProjectConfig &projectConfig)
Generate CMake find_package commands for non-Phoenix dependencies.
PString generateNanobindCmakeSources(const ProjectConfig &projectConfig, const PVecPath &vecClassConfigFile, const GeneratorMode &mode)
Generate the nanobind cmake sources list.
PString generatePhoenixFindModule(const ProjectConfig &projectConfig)
Generate Phoenix find module list.
PMapString generateReplacementMap(const ProjectConfig &projectConfig, const GeneratorMode &mode, const PString &cmakeFindBody, const PString &phoenixPullExtraModule, const PString &phoenixFindModule, const PString &phoenixGlobalDep, const PString &targetLinkBody, const PString &pixiBody, const PString &markdownDepList, const PString &authorListPixi, const PString &nanobindCMakeSources, const PString &rustModuleDeclarations)
Generate the replacement map for placeholders.
PString generateMarkdownDepList(const ProjectConfig &projectConfig)
Generate markdown list of Phoenix dependencies.
PString generatePhoenixPullExtraModule(const ProjectConfig &projectConfig)
Generate Phoenix pull_extra_module commands.
PString generateRustModuleDeclarations(const PVecPath &vecClassConfigFile)
Generate the Rust module declarations to be written into lib.rs.
PString generatePixiBody(const ProjectConfig &projectConfig)
Generate Pixi dependencies.
PString generateTargetLinkBody(const ProjectConfig &projectConfig)
Generate target_link_libraries command.
PString generatePhoenixGlobalDep(const ProjectConfig &projectConfig)
Generate Phoenix global dependencies variable.
ProjectType::ProjectType type
Type of the project to be generated.

References generateAllReplacementData(), generateAuthorListPixi(), generateCmakeFindBody(), generateMarkdownDepList(), generateNanobindCmakeSources(), generatePhoenixFindModule(), generatePhoenixGlobalDep(), generatePhoenixPullExtraModule(), generatePixiBody(), generateReplacementMap(), generateRustModuleDeclarations(), generateTargetLinkBody(), ProjectType::NANOBIND_WRAPPER, ProjectType::RUST, and GeneratorMode::type.

Referenced by generateAllReplacementData(), and simple_project_generator().

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

◆ generateAuthorListPixi()

PString generateAuthorListPixi ( const ProjectConfig & projectConfig)

Generate author list for Pixi.

Parameters
projectConfig: project configuration
Returns
author list for Pixi

Definition at line 198 of file simple_project_generator.cpp.

198 {
199 PString authorListPixi;
200 authorListPixi += "authors = [\n";
201 for(ProjectMembersMap::const_iterator it = projectConfig.authorMap.begin(); it != projectConfig.authorMap.end(); ++it){
202 const PProjectMembers & author = it->second;
203 authorListPixi += " \"" + author.getFirstName() + " " + author.getLastName() + " <" + author.getEmail() + ">\",\n";
204 }
205 authorListPixi += "]\n";
206 return authorListPixi;
207}
Describes a package attributes.
const PString & getFirstName() const
Gets the firstName of the PProjectMembers.
const PString & getLastName() const
Gets the lastName of the PProjectMembers.
const PString & getEmail() const
Gets the email of the PProjectMembers.
ProjectMembersMap authorMap
Map of authors of the project.

References ProjectConfig::authorMap, generateAuthorListPixi(), PProjectMembers::getEmail(), PProjectMembers::getFirstName(), and PProjectMembers::getLastName().

Referenced by generateAllReplacementData(), and generateAuthorListPixi().

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

◆ generateCmakeFindBody()

PString generateCmakeFindBody ( const ProjectConfig & projectConfig)

Generate CMake find_package commands for non-Phoenix dependencies.

Parameters
projectConfig: project configuration
Returns
CMake find_package commands

Definition at line 69 of file simple_project_generator.cpp.

69 {
70 PString cmakeFindBody;
71 for(PackageMap::const_iterator depIt = projectConfig.mapDependencies.begin(); depIt != projectConfig.mapDependencies.end(); ++depIt){
72 const PPackageAttribute & pkgAttr = depIt->second;
73 if(!isPhoenixDependency(pkgAttr.getName())){
74 if(!pkgAttr.getCmakeFind().empty()){
75 cmakeFindBody += "find_package("+pkgAttr.getCmakeFind()+")";
76 }
77 }
78 }
79 return cmakeFindBody;
80}
Describes a package attributes.
const PString & getName() const
Gets the name of the PPackageAttribute.
const PString & getCmakeFind() const
Gets the cmakeFind of the PPackageAttribute.
bool isPhoenixDependency(const PString &packageName)
Check if a package is a Phoenix dependency.
PackageMap mapDependencies
Map of all dependencies of the project with structure PPackageAttribute values.

References generateCmakeFindBody(), PPackageAttribute::getCmakeFind(), PPackageAttribute::getName(), isPhoenixDependency(), and ProjectConfig::mapDependencies.

Referenced by generateAllReplacementData(), and generateCmakeFindBody().

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

◆ generateCppClassesFull()

bool generateCppClassesFull ( const ProjectParam & projectParam)

Generate C++ classes with all standard traits.

Parameters
projectParam: ProjectParam to be used
Returns
true on success, false otherwise

Definition at line 362 of file simple_project_generator.cpp.

362 {
363 PTraitBackendManager manager;
365 manager.addTraitBackend<CppTraitCopy>();
372 return generator_class_full(manager, projectParam);
373}
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
Manager of the Trait backends.
void addTraitBackend()
Add a trait backend into the PTraitBackendManager.
bool generator_class_full(const PTraitBackendManager &manager, const ProjectParam &projectParam)
Generate the full sources and related unit tests from configuration.

References PTraitBackendManager::addTraitBackend(), generateCppClassesFull(), and generator_class_full().

Referenced by generateCppClassesFull(), and simple_project_generate_source().

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

◆ generateMarkdownDepList()

PString generateMarkdownDepList ( const ProjectConfig & projectConfig)

Generate markdown list of Phoenix dependencies.

Parameters
projectConfig: project configuration
Returns
markdown list of Phoenix dependencies

Definition at line 183 of file simple_project_generator.cpp.

183 {
184 PString packageMdList;
185 for(PackageMap::const_iterator depIt = projectConfig.mapDependencies.begin(); depIt != projectConfig.mapDependencies.end(); ++depIt){
186 const PPackageAttribute & pkgAttr = depIt->second;
187 if(isPhoenixDependency(pkgAttr.getName())){
188 packageMdList += "- ["+pkgAttr.getName()+"]("+pkgAttr.getUrl()+")\n";
189 }
190 }
191 return packageMdList;
192}
const PString & getUrl() const
Gets the url of the PPackageAttribute.

References generateMarkdownDepList(), PPackageAttribute::getName(), PPackageAttribute::getUrl(), isPhoenixDependency(), and ProjectConfig::mapDependencies.

Referenced by generateAllReplacementData(), and generateMarkdownDepList().

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

◆ generateNanobindClassesFull()

bool generateNanobindClassesFull ( const ProjectParam & projectParam)

Generate nanobind wrapper classes.

Parameters
projectParam: ProjectParam to be used
Returns
true on success, false otherwise

Definition at line 391 of file simple_project_generator.cpp.

391 {
400 return generator_nanobind_full(manager, projectParam);
401}
Class generator for Nanobind property trait.
Class generator for Nanobind property trait.
Class generator for Nanobind property trait.
Class generator for Nanobind property trait.
Class generator for Nanobind property trait.
Class generator for Nanobind property trait.
Class generator for Nanobind property trait.
Manager of the Trait backends.
void addTraitBackend()
Add a trait backend into the PTraitBackendManager.
bool generator_nanobind_full(const PNanobindTraitBackendManager &manager, const ProjectParam &projectParam)
Generate the full sources and related unit tests from configuration.

References PNanobindTraitBackendManager::addTraitBackend(), generateNanobindClassesFull(), and generator_nanobind_full().

Referenced by generateNanobindClassesFull(), and simple_project_generate_source().

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

◆ generateNanobindCmakeSources()

PString generateNanobindCmakeSources ( const ProjectConfig & projectConfig,
const PVecPath & vecClassConfigFile,
const GeneratorMode & mode )

Generate the nanobind cmake sources list.

Parameters
projectConfig: project configuration
vecClassConfigFile: vector of class config files
mode: generator mode
Returns
nanobind cmake sources list

Definition at line 215 of file simple_project_generator.cpp.

215 {
216 PString nanobindSources;
217 nanobindSources += "# We are now ready to compile the actual extension module\n";
218
219 for(const PPath & classConfigFile : vecClassConfigFile){
220 PPath baseFileName = classConfigFile.getFileName().eraseExtension();
221 PString bindingSource = baseFileName + "_binding.cpp";
222 PString fileModuleName = baseFileName.toLower();
223
224 nanobindSources += "nanobind_add_module(\n";
225 nanobindSources += "\t" + fileModuleName + " # Name of the module\n";
226 nanobindSources += "\tSTABLE_ABI # Compatible Python 3.12+ stable ABI\n";
227 nanobindSources += "\tNB_STATIC # Static linking\n";
228 nanobindSources += "\tLTO # Link-time optimization\n";
229 nanobindSources += "\t" + bindingSource + " # Source file\n";
230 nanobindSources += ")\n";
231 nanobindSources += "target_link_libraries(" + fileModuleName + " PRIVATE " + projectConfig.name.toSnakeCase() + ")\n";
232 nanobindSources += "install(TARGETS " + fileModuleName + " LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES} ARCHIVE DESTINATION ${PYTHON_SITE_PACKAGES})\n\n";
233 }
234
235 return nanobindSources;
236}
PString name
Name of the project.

References generateNanobindCmakeSources(), and ProjectConfig::name.

Referenced by generateAllReplacementData(), and generateNanobindCmakeSources().

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

◆ generatePhoenixFindModule()

PString generatePhoenixFindModule ( const ProjectConfig & projectConfig)

Generate Phoenix find module list.

Parameters
projectConfig: project configuration
Returns
Phoenix find module list

Definition at line 101 of file simple_project_generator.cpp.

101 {
102 PString phoenixFindModule;
103 for(PackageMap::const_iterator depIt = projectConfig.mapDependencies.begin(); depIt != projectConfig.mapDependencies.end(); ++depIt){
104 const PPackageAttribute & pkgAttr = depIt->second;
105 if(isPhoenixDependency(pkgAttr.getName())){
106 phoenixFindModule += " "+pkgAttr.getName();
107 }
108 }
109 return phoenixFindModule;
110}

References generatePhoenixFindModule(), PPackageAttribute::getName(), isPhoenixDependency(), and ProjectConfig::mapDependencies.

Referenced by generateAllReplacementData(), and generatePhoenixFindModule().

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

◆ generatePhoenixGlobalDep()

PString generatePhoenixGlobalDep ( const ProjectConfig & projectConfig)

Generate Phoenix global dependencies variable.

Parameters
projectConfig: project configuration
Returns
Phoenix global dependencies variable

Definition at line 116 of file simple_project_generator.cpp.

116 {
117 PString phoenixGlobalDep;
118 phoenixGlobalDep += "set(" + projectConfig.name.toUpper() + "_TEST_DEPENDENCIES\n";
119 phoenixGlobalDep += "\t" + projectConfig.name.toSnakeCase() + "\n";
120 for(PackageMap::const_reverse_iterator depIt = projectConfig.mapDependencies.rbegin(); depIt != projectConfig.mapDependencies.rend(); ++depIt){
121 const PPackageAttribute & pkgAttr = depIt->second;
122 if(isPhoenixDependency(pkgAttr.getName())){
123 phoenixGlobalDep += "\t"+pkgAttr.getCmakeLib()+"\n";
124 }
125 }
126 phoenixGlobalDep += ")";
127 return phoenixGlobalDep;
128}
const PString & getCmakeLib() const
Gets the cmakeLib of the PPackageAttribute.

References generatePhoenixGlobalDep(), PPackageAttribute::getCmakeLib(), PPackageAttribute::getName(), isPhoenixDependency(), ProjectConfig::mapDependencies, and ProjectConfig::name.

Referenced by generateAllReplacementData(), and generatePhoenixGlobalDep().

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

◆ generatePhoenixPullExtraModule()

PString generatePhoenixPullExtraModule ( const ProjectConfig & projectConfig)

Generate Phoenix pull_extra_module commands.

Parameters
projectConfig: project configuration
Returns
Phoenix pull_extra_module commands

Definition at line 86 of file simple_project_generator.cpp.

86 {
87 PString phoenixPullExtraModule;
88 for(PackageMap::const_iterator depIt = projectConfig.mapDependencies.begin(); depIt != projectConfig.mapDependencies.end(); ++depIt){
89 const PPackageAttribute & pkgAttr = depIt->second;
90 if(isPhoenixDependency(pkgAttr.getName())){
91 phoenixPullExtraModule += "pull_extra_module(\""+pkgAttr.getName()+"\" \""+pkgAttr.getUrl()+"\")\n";
92 }
93 }
94 return phoenixPullExtraModule;
95}

References generatePhoenixPullExtraModule(), PPackageAttribute::getName(), PPackageAttribute::getUrl(), isPhoenixDependency(), and ProjectConfig::mapDependencies.

Referenced by generateAllReplacementData(), and generatePhoenixPullExtraModule().

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

◆ generatePixiBody()

PString generatePixiBody ( const ProjectConfig & projectConfig)

Generate Pixi dependencies.

Parameters
projectConfig: project configuration
Returns
Pixi dependencies

Definition at line 158 of file simple_project_generator.cpp.

158 {
159 PString pixiBody;
160 for(PackageMap::const_iterator depIt = projectConfig.mapDependencies.begin(); depIt != projectConfig.mapDependencies.end(); ++depIt){
161 const PPackageAttribute & pkgAttr = depIt->second;
162 PString pixi_name = pkgAttr.getPixiName().toLower();
163 PString min_version = pkgAttr.getMinVersion();
164 PString max_version = pkgAttr.getMaxVersion();
165 if(pixi_name == "") continue;
166 else if(min_version.empty() && max_version.empty()){
167 pixiBody += pixi_name + " = \"*\"\n";
168 }else if(max_version.empty()){
169 pixiBody += pixi_name + " = \"" + min_version + "\"\n";
170 }else{
171 pixiBody += pixi_name + " = \"" + min_version;
172 if(!min_version.empty() && !max_version.empty()) pixiBody += ",";
173 pixiBody += max_version + "\"\n";
174 }
175 }
176 return pixiBody;
177}
const PString & getMaxVersion() const
Gets the maxVersion of the PPackageAttribute.
const PString & getMinVersion() const
Gets the minVersion of the PPackageAttribute.
const PString & getPixiName() const
Gets the pixiName of the PPackageAttribute.

References generatePixiBody(), PPackageAttribute::getMaxVersion(), PPackageAttribute::getMinVersion(), PPackageAttribute::getPixiName(), and ProjectConfig::mapDependencies.

Referenced by generateAllReplacementData(), and generatePixiBody().

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

◆ generateReplacementMap()

PMapString generateReplacementMap ( const ProjectConfig & projectConfig,
const GeneratorMode & mode,
const PString & cmakeFindBody,
const PString & phoenixPullExtraModule,
const PString & phoenixFindModule,
const PString & phoenixGlobalDep,
const PString & targetLinkBody,
const PString & pixiBody,
const PString & markdownDepList,
const PString & authorListPixi,
const PString & nanobindCMakeSources,
const PString & rustModuleDeclarations )

Generate the replacement map for placeholders.

Parameters
projectConfig: project configuration
mode: generator mode
cmakeFindBody: CMake find_package commands
phoenixPullExtraModule: Phoenix pull_extra_module commands
phoenixFindModule: Phoenix find module list
phoenixGlobalDep: Phoenix global dependencies variable
targetLinkBody: target_link_libraries command
pixiBody: Pixi dependencies
authorListPixi: author list for Pixi
nanobindCMakeSources: nanobind cmake sources list
rustModuleDeclarations: rust module declarations for lib.rs
Returns
replacement map for placeholders

Definition at line 264 of file simple_project_generator.cpp.

268{
269 PMapString mapReplace;
271 mapReplace["xxxnanobind_sourcesxxx"] = nanobindCMakeSources; //nanobind cmake sources
272 }
273 if(mode.type == ProjectType::RUST){
274 mapReplace["XXXRustModuleDeclarationsXXX"] = rustModuleDeclarations; //rust module declarations for lib.rs
275 }
276 mapReplace["XXXProjectNameXXX"] = projectConfig.name; //project name
277 mapReplace["XXXPROJECT_NAMEXXX"] = projectConfig.name.toUpper(); //project name uppercase
278 mapReplace["xxxproject_namexxx"] = projectConfig.name.toSnakeCase(); //project library
279 mapReplace["XXXProjectNameDescriptionXXX"] = projectConfig.description; //description
280 mapReplace["XXXProjectNameUrlXXX"] = projectConfig.url; //project url
281 mapReplace["XXXProjectVersionXXX"] = projectConfig.version; //project version
282 mapReplace["XXXProjectNameHomepageUrlXXX"] = projectConfig.url; //project doc url (TODO add it or deduce it from the project url for gitlab)
283 mapReplace["XXXProjectNameRunnerTagXXX"] = projectConfig.runnerTag; //Project CI runner tag
284 mapReplace["XXXProjectFindPackageDependenciesXXX"] = cmakeFindBody; //project find_package
285 mapReplace["XXXProjectPhoenixDependenciesXXX"] = phoenixPullExtraModule; //project pull_extra_module
286 mapReplace["XXXProjectNameCMakeFindDependenciesXXX"] = phoenixFindModule; //project dependencies of phoenix_create_find
287 mapReplace["XXXProjectDependenciesCMakeVarXXX"] = phoenixGlobalDep; //cmake variable to hold test dependencies
288 mapReplace["XXXProjectNameTargetLinkLibDependenciesXXX"] = targetLinkBody; //full target_link_library command of generated lib
289 mapReplace["XXXCxxWorkflowUrlXXX"] = projectConfig.ciToolkitUrl+"@"+projectConfig.ciToolkitVersion; //Url and version of the CI workflow
290 mapReplace["XXXGitlabPagesUrlXXX"] = getGitlabDocUrl(projectConfig.url); //group to which the project belongs to
291 mapReplace["xxxphoenixprojectpixipackagenamexxx"] = projectConfig.name.toLower(); //name of the pixi package
292 mapReplace["xxxprojectnamepixiextradependenciesxxx"] = pixiBody; //extra pixi dependencies
293 mapReplace["XXXProjectNameMarkdownListDependenciesXXX"] = markdownDepList; //markdown list of Phoenix dependencies
294 mapReplace["XXXProjectAuthorListPixiXXX"] = authorListPixi; //author list for pixi.toml
295 return mapReplace;
296}
PString getGitlabDocUrl(const PString &projectUrl)
Get the documentation url of the given project url if possible.
PString description
Description 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 version
Project version.

References ProjectConfig::ciToolkitUrl, ProjectConfig::ciToolkitVersion, ProjectConfig::description, generateReplacementMap(), getGitlabDocUrl(), ProjectConfig::name, ProjectType::NANOBIND_WRAPPER, ProjectConfig::runnerTag, ProjectType::RUST, GeneratorMode::type, ProjectConfig::url, and ProjectConfig::version.

Referenced by generateAllReplacementData(), and generateReplacementMap().

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

◆ generateRustClassesFull()

bool generateRustClassesFull ( const ProjectParam & projectParam)

Generate rust classes.

Parameters
projectParam: ProjectParam to be used
Returns
true on success, false otherwise

Definition at line 408 of file simple_project_generator.cpp.

408 {
409 ProjectParam updatedParam(projectParam);
410 updatedParam.mode.moduleName = updatedParam.name.toLower(); //Cargo crate name, matches xxxphoenixprojectpixipackagenamexxx
413 return generator_rust_class_full(manager, updatedParam);
414}
Manager of the Rust trait backends.
void addTraitBackend()
Add a trait backend into the PRustTraitBackendManager.
Rust trait generating getters and setters for every attribute.
bool generator_rust_class_full(const PRustTraitBackendManager &manager, const ProjectParam &projectParam)
Generate the full Rust sources (and related integration tests) from configuration.
Set of parameters to generate a project.

References PRustTraitBackendManager::addTraitBackend(), generateRustClassesFull(), generator_rust_class_full(), ProjectParam::mode, GeneratorMode::moduleName, and ProjectParam::name.

Referenced by generateRustClassesFull(), and simple_project_generate_source().

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

◆ generateRustModuleDeclarations()

PString generateRustModuleDeclarations ( const PVecPath & vecClassConfigFile)

Generate the Rust module declarations to be written into lib.rs.

Parameters
vecClassConfigFile: vector of class config files
Returns
rust module declarations (eg "pub mod shadok;\npub mod gibis;\n")

Definition at line 242 of file simple_project_generator.cpp.

242 {
243 PString decls;
244 for(const PPath & classConfigFile : vecClassConfigFile){
245 decls += "pub mod " + classConfigFile.getFileName().eraseExtension().toSnakeCase() + ";\n";
246 }
247 return decls;
248}

References generateRustModuleDeclarations().

Referenced by generateAllReplacementData(), and generateRustModuleDeclarations().

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

◆ generateTargetLinkBody()

PString generateTargetLinkBody ( const ProjectConfig & projectConfig)

Generate target_link_libraries command.

Parameters
projectConfig: project configuration
Returns
target_link_libraries command

Definition at line 134 of file simple_project_generator.cpp.

134 {
135 PString targetLinkBody;
136 targetLinkBody += "target_link_libraries("+projectConfig.name.toSnakeCase()+" ";
137 for(PackageMap::const_iterator depIt = projectConfig.mapDependencies.begin(); depIt != projectConfig.mapDependencies.end(); ++depIt){
138 const PPackageAttribute & pkgAttr = depIt->second;
139 if(!isPhoenixDependency(pkgAttr.getName())){
140 targetLinkBody += pkgAttr.getCmakeLib()+" ";
141 }
142 }
143 // Add Phoenix dependencies (to ensure proper linking even if phoenix_create_find should handle it)
144 for(PackageMap::const_iterator depIt = projectConfig.mapDependencies.begin(); depIt != projectConfig.mapDependencies.end(); ++depIt){
145 const PPackageAttribute & pkgAttr = depIt->second;
146 if(isPhoenixDependency(pkgAttr.getName())){
147 targetLinkBody += pkgAttr.getCmakeLib()+" ";
148 }
149 }
150 targetLinkBody += ")\n";
151 return targetLinkBody;
152}

References generateTargetLinkBody(), PPackageAttribute::getCmakeLib(), PPackageAttribute::getName(), isPhoenixDependency(), ProjectConfig::mapDependencies, and ProjectConfig::name.

Referenced by generateAllReplacementData(), and generateTargetLinkBody().

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

◆ generateWrapperClassesFull()

bool generateWrapperClassesFull ( const ProjectParam & projectParam)

Generate wrapper classes.

Parameters
projectParam: ProjectParam to be used
Returns
true on success, false otherwise

Definition at line 379 of file simple_project_generator.cpp.

379 {
384 return wrapper_generator_class_full(manager, projectParam);
385}
Manager of the Trait backends.
void addTraitBackend()
Add a trait backend into the PWrapperTraitBackendManager.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
bool wrapper_generator_class_full(const PWrapperTraitBackendManager &manager, const ProjectParam &projectParam)
Generate the full sources and related unit tests from configuration.

References PWrapperTraitBackendManager::addTraitBackend(), generateWrapperClassesFull(), and wrapper_generator_class_full().

Referenced by generateWrapperClassesFull(), and simple_project_generate_source().

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

◆ isPhoenixDependency()

bool isPhoenixDependency ( const PString & packageName)

Check if a package is a Phoenix dependency.

Parameters
packageName: name of the package
Returns
true if it's a Phoenix dependency, false otherwise

Definition at line 61 of file simple_project_generator.cpp.

61 {
62 return (packageName.isSameBegining("Phoenix") || packageName.isSameBegining("phoenix"));
63}

References isPhoenixDependency().

Referenced by generateCmakeFindBody(), generateMarkdownDepList(), generatePhoenixFindModule(), generatePhoenixGlobalDep(), generatePhoenixPullExtraModule(), generateTargetLinkBody(), and isPhoenixDependency().

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

◆ simple_project_generate_source()

bool simple_project_generate_source ( const ProjectParam & projectParam)

Save generated sources of project.

Parameters
projectParam: ProjectParam to be used
Returns
true on success, false otherwise

Definition at line 440 of file simple_project_generator.cpp.

440 {
441 switch(projectParam.mode.type){
442 case ProjectType::CPP:
443 return generateCppClassesFull(projectParam);
445 return generateWrapperClassesFull(projectParam);
447 {
448 ProjectParam strip(stripNanobindUnsupportedType(projectParam));
450 }
452 return generateRustClassesFull(projectParam);
453 default:
454 return false;
455 }
456}
bool generateNanobindClassesFull(const ProjectParam &projectParam)
Generate nanobind wrapper classes.
ProjectParam stripNanobindUnsupportedType(const ProjectParam &projectParam)
Create a ProjectParam with PString and PPath converted into std::string.
bool generateCppClassesFull(const ProjectParam &projectParam)
Generate C++ classes with all standard traits.
bool generateRustClassesFull(const ProjectParam &projectParam)
Generate rust classes.
bool generateWrapperClassesFull(const ProjectParam &projectParam)
Generate wrapper classes.
GeneratorMode mode
Mode to be used to generate the project.

References ProjectType::CPP, generateCppClassesFull(), generateNanobindClassesFull(), generateRustClassesFull(), generateWrapperClassesFull(), ProjectParam::mode, ProjectType::NANOBIND_WRAPPER, ProjectType::RUST, simple_project_generate_source(), stripNanobindUnsupportedType(), GeneratorMode::type, and ProjectType::WRAPPER.

Referenced by simple_project_generate_source(), and simple_project_generator().

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

◆ simple_project_generator()

bool simple_project_generator ( const PPath & descriptionFile,
const PVecPath & vecClassConfigFile,
const PString & projectType,
const GeneratorMode & mode )

Create a simple project from a configuration.

Parameters
descriptionFile: description of the full project
vecClassConfigFile: vector of class configuration files (.pdata files)
projectType: type of the project (SimpleCpp)
mode: all modes of the generator (data/check/type/config stream)
Returns
true on success, false otherwise

Definition at line 465 of file simple_project_generator.cpp.

467{
468 //First, let's read the toml config of the project
469 ProjectConfig projectConfig;
470 if(!project_generator_loadConfig(projectConfig, descriptionFile)){
471 std::cerr << "simple_project_generator : cannot parse project description file '"<<descriptionFile<<"'" << std::endl;
472 return false;
473 }
474 //Then look in the config files if the packages exists
475 if(!project_generator_loadPackageInfo(projectConfig)){
476 std::cerr << "simple_project_generator : cannot find package info of project '"<<projectConfig.name<<"'" << std::endl;
477 return false;
478 }
479 // Generate replacement data
480 PMapString mapReplace = generateAllReplacementData(projectConfig, mode, vecClassConfigFile);
481 PPath inputConfigPlaceholderDir = PPath::getProgramPrefix() / PPath("share") / PPath("PhoenixGenerator") / PPath("Projects") / PPath(projectType), outputPath("./");
482 if(!directory_replace_placeholder(outputPath, inputConfigPlaceholderDir, mapReplace)){
483 std::cerr << "simple_project_generator : cannot replace placeholder in project generation '"<<projectConfig.name<<"'" << std::endl;
484 return false;
485 }
486 PPath mainPath = PPath(".") / PPath(projectConfig.name);
487 PPath srcPath = mainPath / PPath("src"), pdataDir = mainPath / PPath("pdata");
488 if(!pdataDir.createDirectory()){
489 std::cerr << "simple_project_generator : cannot create pdata directory '"<<pdataDir<<"'" << std::endl;
490 return false;
491 }
492 ProjectParam param;
493 param.mode = mode;
494 param.name = projectConfig.name;
495 param.version = projectConfig.version;
496 param.outputProjectDir = mainPath;
497 param.outputSourceDir = srcPath;
499 param.outputTestDir = mainPath / PPath("TESTS");
500 }else if(param.mode.type == ProjectType::WRAPPER || param.mode.type == ProjectType::RUST){
501 param.outputTestDir = mainPath / PPath("tests");
502 }
503
504 if(!simple_project_load_config(param, pdataDir, vecClassConfigFile)){
505 std::cerr << "simple_project_generator : cannot load config to generate project in '"<<srcPath<<"'" << std::endl;
506 return false;
507 }
509 std::cerr << "simple_project_generator : cannot generate sources in '"<<srcPath<<"'" << std::endl;
510 return false;
511 }
512 // Generate class generator script
513 if(!generateClassGeneratorScript(vecClassConfigFile, pdataDir, param.mode)){
514 std::cerr << "simple_project_generator : cannot generate class generator script in pdata directory '"<<pdataDir<<"'" << std::endl;
515 return false;
516 }
517 return true;
518}
bool project_generator_loadPackageInfo(ProjectConfig &config)
This function should load the package info file from share/PhoenixGenerator/Packages and retrieve the...
bool project_generator_loadConfig(ProjectConfig &config, const PPath &descriptionFile)
Load the project configuration.
bool generateClassGeneratorScript(const PVecPath &vecClassConfigFile, const PPath &scriptDir, const GeneratorMode &mode)
Generate a bash script to re generate all the classes from their pdata configuration files.
PMapString generateAllReplacementData(const ProjectConfig &projectConfig, const GeneratorMode &mode, const PVecPath &vecClassConfigFile)
Generate all replacement data for project generation.
bool simple_project_load_config(ProjectParam &param, const PPath &pdataDir, const PVecPath &vecClassConfigFile)
Load configuration pdata of generated sources.
bool simple_project_generate_source(const ProjectParam &projectParam)
Save generated sources of project.
Configuration of the project.
PPath outputProjectDir
Output path of the full project.
PString version
Version of the project.
PPath outputTestDir
Output path of the unit tests.
PString name
Name of the project.
PPath outputSourceDir
Output path of the sources.

References ProjectType::CPP, generateAllReplacementData(), generateClassGeneratorScript(), ProjectParam::mode, ProjectConfig::name, ProjectParam::name, ProjectType::NANOBIND_WRAPPER, ProjectParam::outputProjectDir, ProjectParam::outputSourceDir, ProjectParam::outputTestDir, project_generator_loadConfig(), project_generator_loadPackageInfo(), ProjectType::RUST, simple_project_generate_source(), simple_project_generator(), simple_project_load_config(), GeneratorMode::type, ProjectConfig::version, ProjectParam::version, and ProjectType::WRAPPER.

Referenced by simple_project_generator().

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

◆ simple_project_load_config()

bool simple_project_load_config ( ProjectParam & param,
const PPath & pdataDir,
const PVecPath & vecClassConfigFile )

Load configuration pdata of generated sources.

Parameters
[out]param: ProjectParam to be updated
pdataDir: directory where to save pdata configuration
vecClassConfigFile: vector of class configuration files (.pdata files)
Returns
true on success, false otherwise

Definition at line 337 of file simple_project_generator.cpp.

337 {
338 bool b(true);
339 for(const PPath & classConfigFile : vecClassConfigFile){
340 PDataConfig dataConfig;
341 dataConfig.getFileName() = classConfigFile;
342 if(!parserClassConfig(dataConfig.getVecClassConfig(), dataConfig.getVecInclude(), classConfigFile)){
343 std::cerr << "simple_project_load_config : can't load file '" << classConfigFile << "'" << std::endl;
344 b = false; //Best effort strategy
345 }
346 param.vecDataConfig.push_back(dataConfig);
347
348 PPath destFile = pdataDir / classConfigFile.getFileName();
349 PString fileContent = classConfigFile.loadFileContent();
350 if(!destFile.saveFileContent(fileContent)){
351 std::cerr << "simple_project_load_config : cannot copy pdata file to project pdata directory '"<<destFile<<"'" << std::endl;
352 b = false; //Best effort strategy
353 }
354 }
355 return b;
356}
Class to describe a basic class.
Definition PDataConfig.h:17
const PVecClassConfig & getVecClassConfig() const
Get the vector of all config class of the current pdata file.
const PPath & getFileName() const
Get the file name of the current PDataConfig.
const PVecPath & getVecInclude() const
Get the vector of all include files of the current pdata file.
bool parserClassConfig(std::vector< PClassConfig > &listClassConfig, PVecPath &listInclude, const PPath &fileName)
Parser list class config.
PVecDataConfig vecDataConfig
Configuration of classes to be generated.

References PDataConfig::getFileName(), PDataConfig::getVecClassConfig(), PDataConfig::getVecInclude(), parserClassConfig(), simple_project_load_config(), and ProjectParam::vecDataConfig.

Referenced by simple_project_generator(), and simple_project_load_config().

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

◆ stripNanobindUnsupportedType()

ProjectParam stripNanobindUnsupportedType ( const ProjectParam & projectParam)

Create a ProjectParam with PString and PPath converted into std::string.

Parameters
projectParam: ProjectParam to be converted
Returns
converted ProjectParam

Definition at line 420 of file simple_project_generator.cpp.

420 {
421 ProjectParam output(projectParam);
422 PVecDataConfig & vecConfig = output.vecDataConfig;
423 for(PVecDataConfig::iterator itConfig(vecConfig.begin()); itConfig != vecConfig.end(); ++itConfig){
424 PVecClassConfig & vecClass = itConfig->getVecClassConfig();
425 for(PVecClassConfig::iterator itClass(vecClass.begin()); itClass != vecClass.end(); ++itClass){
426 PVecClassAttribute & vecAttr = itClass->getListAttribute();
427 for(PVecClassAttribute::iterator itAttr(vecAttr.begin()); itAttr != vecAttr.end(); ++itAttr){
428 PString name = itAttr->getType();
429 itAttr->setType(name.replace("PPath", "std::string").replace("PString", "std::string"));
430 }
431 }
432 }
433 return output;
434}
std::vector< PDataConfig > PVecDataConfig
Definition PDataConfig.h:48
std::vector< PClassAttribute > PVecClassAttribute
Definition PDataConfig.h:13
std::vector< PClassConfig > PVecClassConfig
Definition PDataConfig.h:14

References stripNanobindUnsupportedType(), and ProjectParam::vecDataConfig.

Referenced by simple_project_generate_source(), and stripNanobindUnsupportedType().

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