9#include "directory_replace_placeholder.h"
62 return (packageName.isSameBegining(
"Phoenix") || packageName.isSameBegining(
"phoenix"));
70 PString cmakeFindBody;
75 cmakeFindBody +=
"find_package("+pkgAttr.
getCmakeFind()+
")";
87 PString phoenixPullExtraModule;
91 phoenixPullExtraModule +=
"pull_extra_module(\""+pkgAttr.
getName()+
"\" \""+pkgAttr.
getUrl()+
"\")\n";
94 return phoenixPullExtraModule;
102 PString phoenixFindModule;
106 phoenixFindModule +=
" "+pkgAttr.
getName();
109 return phoenixFindModule;
117 PString phoenixGlobalDep;
118 phoenixGlobalDep +=
"set(" + projectConfig.
name.toUpper() +
"_TEST_DEPENDENCIES\n";
119 phoenixGlobalDep +=
"\t" + projectConfig.
name.toSnakeCase() +
"\n";
123 phoenixGlobalDep +=
"\t"+pkgAttr.
getCmakeLib()+
"\n";
126 phoenixGlobalDep +=
")";
127 return phoenixGlobalDep;
135 PString targetLinkBody;
136 targetLinkBody +=
"target_link_libraries("+projectConfig.
name.toSnakeCase()+
" ";
150 targetLinkBody +=
")\n";
151 return targetLinkBody;
162 PString pixi_name = pkgAttr.
getPixiName().toLower();
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";
171 pixiBody += pixi_name +
" = \"" + min_version;
172 if(!min_version.empty() && !max_version.empty()) pixiBody +=
",";
173 pixiBody += max_version +
"\"\n";
184 PString packageMdList;
188 packageMdList +=
"- ["+pkgAttr.
getName()+
"]("+pkgAttr.
getUrl()+
")\n";
191 return packageMdList;
199 PString authorListPixi;
200 authorListPixi +=
"authors = [\n";
201 for(ProjectMembersMap::const_iterator it = projectConfig.
authorMap.begin(); it != projectConfig.
authorMap.end(); ++it){
205 authorListPixi +=
"]\n";
206 return authorListPixi;
216 PString nanobindSources;
217 nanobindSources +=
"# We are now ready to compile the actual extension module\n";
219 for(
const PPath & classConfigFile : vecClassConfigFile){
220 PPath baseFileName = classConfigFile.getFileName().eraseExtension();
221 PString bindingSource = baseFileName +
"_binding.cpp";
222 PString fileModuleName = baseFileName.toLower();
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";
235 return nanobindSources;
244 for(
const PPath & classConfigFile : vecClassConfigFile){
245 decls +=
"pub mod " + classConfigFile.getFileName().eraseExtension().toSnakeCase() +
";\n";
265 const PString & phoenixFindModule,
const PString & phoenixGlobalDep,
const PString & targetLinkBody,
266 const PString & pixiBody,
const PString & markdownDepList,
const PString & authorListPixi,
const PString & nanobindCMakeSources,
267 const PString & rustModuleDeclarations)
269 PMapString mapReplace;
271 mapReplace[
"xxxnanobind_sourcesxxx"] = nanobindCMakeSources;
274 mapReplace[
"XXXRustModuleDeclarationsXXX"] = rustModuleDeclarations;
276 mapReplace[
"XXXProjectNameXXX"] = projectConfig.
name;
277 mapReplace[
"XXXPROJECT_NAMEXXX"] = projectConfig.
name.toUpper();
278 mapReplace[
"xxxproject_namexxx"] = projectConfig.
name.toSnakeCase();
279 mapReplace[
"XXXProjectNameDescriptionXXX"] = projectConfig.
description;
280 mapReplace[
"XXXProjectNameUrlXXX"] = projectConfig.
url;
281 mapReplace[
"XXXProjectVersionXXX"] = projectConfig.
version;
282 mapReplace[
"XXXProjectNameHomepageUrlXXX"] = projectConfig.
url;
283 mapReplace[
"XXXProjectNameRunnerTagXXX"] = projectConfig.
runnerTag;
284 mapReplace[
"XXXProjectFindPackageDependenciesXXX"] = cmakeFindBody;
285 mapReplace[
"XXXProjectPhoenixDependenciesXXX"] = phoenixPullExtraModule;
286 mapReplace[
"XXXProjectNameCMakeFindDependenciesXXX"] = phoenixFindModule;
287 mapReplace[
"XXXProjectDependenciesCMakeVarXXX"] = phoenixGlobalDep;
288 mapReplace[
"XXXProjectNameTargetLinkLibDependenciesXXX"] = targetLinkBody;
291 mapReplace[
"xxxphoenixprojectpixipackagenamexxx"] = projectConfig.
name.toLower();
292 mapReplace[
"xxxprojectnamepixiextradependenciesxxx"] = pixiBody;
293 mapReplace[
"XXXProjectNameMarkdownListDependenciesXXX"] = markdownDepList;
294 mapReplace[
"XXXProjectAuthorListPixiXXX"] = authorListPixi;
312 PString nanobindCMakeSources;
316 PString rustModuleDeclarations;
322 PString dateStr = ctime(&(timestamp = time(
nullptr)));
323 dateStr = dateStr.eraseLastChar(
"\n");
327 phoenixFindModule, phoenixGlobalDep, targetLinkBody,
328 pixiBody, markdownDepList, authorListPixi, nanobindCMakeSources, rustModuleDeclarations);
339 for(
const PPath & classConfigFile : vecClassConfigFile){
343 std::cerr <<
"simple_project_load_config : can't load file '" << classConfigFile <<
"'" << std::endl;
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;
423 for(PVecDataConfig::iterator itConfig(vecConfig.begin()); itConfig != vecConfig.end(); ++itConfig){
425 for(PVecClassConfig::iterator itClass(vecClass.begin()); itClass != vecClass.end(); ++itClass){
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"));
471 std::cerr <<
"simple_project_generator : cannot parse project description file '"<<descriptionFile<<
"'" << std::endl;
476 std::cerr <<
"simple_project_generator : cannot find package info of project '"<<projectConfig.
name<<
"'" << std::endl;
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;
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;
505 std::cerr <<
"simple_project_generator : cannot load config to generate project in '"<<srcPath<<
"'" << std::endl;
509 std::cerr <<
"simple_project_generator : cannot generate sources in '"<<srcPath<<
"'" << std::endl;
514 std::cerr <<
"simple_project_generator : cannot generate class generator script in pdata directory '"<<pdataDir<<
"'" << std::endl;
std::vector< PDataConfig > PVecDataConfig
std::vector< PClassAttribute > PVecClassAttribute
std::vector< PClassConfig > PVecClassConfig
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.
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.
Class to describe a basic class.
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.
Manager of the Trait backends.
void addTraitBackend()
Add a trait backend into the PTraitBackendManager.
Describes a package attributes.
const PString & getName() const
Gets the name of the PPackageAttribute.
const PString & getMaxVersion() const
Gets the maxVersion of the PPackageAttribute.
const PString & getUrl() const
Gets the url of the PPackageAttribute.
const PString & getCmakeFind() const
Gets the cmakeFind of the PPackageAttribute.
const PString & getCmakeLib() const
Gets the cmakeLib of the PPackageAttribute.
const PString & getMinVersion() const
Gets the minVersion of the PPackageAttribute.
const PString & getPixiName() const
Gets the pixiName of the PPackageAttribute.
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.
Manager of the Rust trait backends.
void addTraitBackend()
Add a trait backend into the PRustTraitBackendManager.
Manager of the Trait backends.
void addTraitBackend()
Add a trait backend into the PTraitBackendManager.
Manager of the Trait backends.
void addTraitBackend()
Add a trait backend into the PWrapperTraitBackendManager.
Rust trait generating getters and setters for every attribute.
Class generator for setter trait.
Class generator for setter trait.
Class generator for setter trait.
bool generator_class_full(const PTraitBackendManager &manager, const ProjectParam &projectParam)
Generate the full sources and related unit tests from configuration.
bool generator_rust_class_full(const PRustTraitBackendManager &manager, const ProjectParam &projectParam)
Generate the full Rust sources (and related integration tests) from configuration.
PString getGitlabDocUrl(const PString &projectUrl)
Get the documentation url of the given project url if possible.
bool generator_nanobind_full(const PNanobindTraitBackendManager &manager, const ProjectParam &projectParam)
Generate the full sources and related unit tests from configuration.
bool parserClassConfig(std::vector< PClassConfig > &listClassConfig, PVecPath &listInclude, const PPath &fileName)
Parser list class config.
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 ¶m, const PPath &pdataDir, const PVecPath &vecClassConfigFile)
Load configuration pdata of generated sources.
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 simple_project_generate_source(const ProjectParam &projectParam)
Save generated sources of project.
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.
PString generateNanobindCmakeSources(const ProjectConfig &projectConfig, const PVecPath &vecClassConfigFile, const GeneratorMode &mode)
Generate the nanobind cmake sources list.
bool generateCppClassesFull(const ProjectParam &projectParam)
Generate C++ classes with all standard traits.
bool isPhoenixDependency(const PString &packageName)
Check if a package is a Phoenix dependency.
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.
bool generateRustClassesFull(const ProjectParam &projectParam)
Generate rust classes.
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.
bool generateWrapperClassesFull(const ProjectParam &projectParam)
Generate wrapper classes.
bool simple_project_generator(const PPath &descriptionFile, const PVecPath &vecClassConfigFile, const PString &projectType, const GeneratorMode &mode)
Create a simple project from a configuration.
PString generateTargetLinkBody(const ProjectConfig &projectConfig)
Generate target_link_libraries command.
PString generatePhoenixGlobalDep(const ProjectConfig &projectConfig)
Generate Phoenix global dependencies variable.
PString moduleName
Name of the wrapper python module.
ProjectType::ProjectType type
Type of the project to be generated.
Configuration of the project.
PString description
Description of the project.
PString name
Name of the project.
PackageMap mapDependencies
Map of all dependencies of the project with structure PPackageAttribute values.
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 version
Project version.
Set of parameters to generate a project.
PPath outputProjectDir
Output path of the full project.
GeneratorMode mode
Mode to be used to generate the project.
PString version
Version of the project.
PPath outputTestDir
Output path of the unit tests.
PVecDataConfig vecDataConfig
Configuration of classes to be generated.
PString name
Name of the project.
PPath outputSourceDir
Output path of the sources.
bool wrapper_generator_class_full(const PWrapperTraitBackendManager &manager, const ProjectParam &projectParam)
Generate the full sources and related unit tests from configuration.