PhoenixGenerator  2.0.0
Set of tools to generate code
project_generator.cpp File Reference
#include "parser_toml.h"
#include "cmakelist_generator.h"
#include "gitlab_doc.h"
#include "wrapper_generator.h"
#include "project_generator.h"
+ Include dependency graph for project_generator.cpp:

Go to the source code of this file.

Functions

bool project_generator (const PPath &descriptionFile, const PPath &configFile, bool isPythonWrapper)
 Generate a full project with PhoenixDataStream and PhoenixTypeStream. More...
 
bool project_generator_cmakeListsMain (const PPath &fileName, const ProjectConfig &projectConfig, const PString &baseConfigClassName)
 Create the main CMakeLists.txt of the project directory. More...
 
bool project_generator_cmakeListsSrc (const PPath &fileName, const PString &projectName, const PString &libName)
 Create the CMakeLists.txt of the src directory. More...
 
bool project_generator_cmakeListsTest (const PPath &fileName, const PString &baseConfigClassName)
 Create the main CMakeLists.txt of the project directory. More...
 
bool project_generator_gitignore (const PPath &fileName)
 Create the .gitignore of the project. More...
 
bool project_generator_gitlabci (const PPath &fileName, const ProjectConfig &projectConfig)
 Create the .gitlab-ci.yml of the project. More...
 
bool project_generator_loadConfig (ProjectConfig &config, const PPath &descriptionFile)
 Load the project configuration. More...
 
bool project_generator_readme (const PPath &fileName, const ProjectConfig &projectConfig)
 Create the readme of the project directory. More...
 

Function Documentation

◆ project_generator()

bool project_generator ( const PPath descriptionFile,
const PPath configFile,
bool  isPythonWrapper 
)

Generate a full project with PhoenixDataStream and PhoenixTypeStream.

Parameters
descriptionFile: description of the full project
configFile: configuration file of the
isPythonWrapper: true if we want to generate a Python wrapper
Returns
true on success, false otherwise

Definition at line 292 of file project_generator.cpp.

292  {
293  //First, let's read the toml config of the project
294  ProjectConfig projectConfig;
295  if(!project_generator_loadConfig(projectConfig, descriptionFile)){
296  std::cerr << "project_generator : cannot parse project description file '"<<descriptionFile<<"'" << std::endl;
297  return false;
298  }
299  //Then, let's create the hierarchy
300  PPath mainProjectDir(projectConfig.name);
301  if(!mainProjectDir.createDirectory()){
302  std::cerr << "project_generator : cannot create main directory of project '"<<mainProjectDir<<"'" << std::endl;
303  return false;
304  }
305  //And src dir
306  PPath mainProjectSrc(mainProjectDir / PPath("src"));
307  if(!mainProjectSrc.createDirectory()){
308  std::cerr << "project_generator : cannot create source directory of project '"<<mainProjectSrc<<"'" << std::endl;
309  return false;
310  }
311  //Let's generate sources
312  PString className = configFile.getFileName().eraseExtension();
313  if(!saveParserClassConfig(mainProjectSrc / className, configFile, true, true, true, mainProjectDir, projectConfig.name.toLower())){
314  std::cerr << "project_generator : can't save file '"<<className<<"'[.h or .cpp]" << std::endl;
315  return false;
316  }
317  //Now, some CMakeLists.txt of the sources
318  PPath cmakeListsSrc(mainProjectSrc / PPath("CMakeLists.txt"));
319  if(!project_generator_cmakeListsSrc(cmakeListsSrc, projectConfig.name, projectConfig.name.toLower())){return false;}
320  //The main CMakeLists
321  PPath cmakeListsMain(mainProjectDir / PPath("CMakeLists.txt"));
322  if(!project_generator_cmakeListsMain(cmakeListsMain, projectConfig, configFile.getFileName().eraseExtension())){return false;}
323  //CMakeLists of the tests
324  PPath cmakeListsTest(mainProjectDir / PPath("TESTS/CMakeLists.txt"));
325  if(!project_generator_cmakeListsTest(cmakeListsTest, configFile.getFileName().eraseExtension())){return false;}
326  //The readme
327  PPath readmeFile(mainProjectDir / PPath("README.md"));
328  if(!project_generator_readme(readmeFile, projectConfig)){return false;}
329  //The gitignore
330  PPath gitignoreFile(mainProjectDir / PPath(".gitignore"));
331  if(!project_generator_gitignore(gitignoreFile)){return false;}
332 
333  PPath gitlabciFile(mainProjectDir / PPath(".gitlab-ci.yml"));
334  if(!project_generator_gitlabci(gitlabciFile, projectConfig)){return false;}
335  if(isPythonWrapper){
336  return project_wrapper_generator(projectConfig, configFile);
337  }
338  return true;
339 }
Path of a directory or a file.
Definition: PPath.h:17
PPath & eraseExtension()
Erase the extension of the PPath.
Definition: PPath.cpp:292
PPath getFileName() const
Get the name of the file, from last char to /.
Definition: PPath.cpp:172
Extends the std::string.
Definition: PString.h:16
PString toLower() const
Convert PString in lower case.
Definition: PString.cpp:598
bool saveParserClassConfig(const PPath &baseFileNameOutput, const PPath &fileName, bool enableDataStream, bool enableTypeStream, bool enableUnitTest, const PPath &testParentDir, const PString &libName)
Parser list class config.
bool project_generator_cmakeListsMain(const PPath &fileName, const ProjectConfig &projectConfig, const PString &baseConfigClassName)
Create the main CMakeLists.txt of the project directory.
bool project_generator_cmakeListsSrc(const PPath &fileName, const PString &projectName, const PString &libName)
Create the CMakeLists.txt of the src directory.
bool project_generator_gitlabci(const PPath &fileName, const ProjectConfig &projectConfig)
Create the .gitlab-ci.yml of the project.
bool project_generator_gitignore(const PPath &fileName)
Create the .gitignore of the project.
bool project_generator_readme(const PPath &fileName, const ProjectConfig &projectConfig)
Create the readme of the project directory.
bool project_generator_cmakeListsTest(const PPath &fileName, const PString &baseConfigClassName)
Create the main CMakeLists.txt of the project directory.
bool project_generator_loadConfig(ProjectConfig &config, const PPath &descriptionFile)
Load the project configuration.
Configuration of the project.
PString name
Name of the project.
bool project_wrapper_generator(const ProjectConfig &projectConfig, const PPath &configFile)
Generate a full python wrapper project with PhoenixDataStream and PhoenixTypeStream.

References PPath::createDirectory(), PPath::eraseExtension(), PPath::getFileName(), ProjectConfig::name, project_generator_cmakeListsMain(), project_generator_cmakeListsSrc(), project_generator_cmakeListsTest(), project_generator_gitignore(), project_generator_gitlabci(), project_generator_loadConfig(), project_generator_readme(), project_wrapper_generator(), saveParserClassConfig(), and PString::toLower().

+ Here is the call graph for this function:

◆ project_generator_cmakeListsMain()

bool project_generator_cmakeListsMain ( const PPath fileName,
const ProjectConfig projectConfig,
const PString baseConfigClassName 
)

Create the main CMakeLists.txt of the project directory.

Parameters
fileName: name of the file to be created
projectConfig: config of the project
baseConfigClassName: base name of the config class file
Returns
true on success, false otherwise

Definition at line 82 of file project_generator.cpp.

82  {
83  PString body;
84  body += getCMakeListsHeader();
85 
86  body += "cmake_minimum_required(VERSION 3.10)\n";
87  body += "project("+projectConfig.name+")\n";
88 
89  body += "\nfind_package(PhoenixCMake REQUIRED)\n\n";
90 
91  body += "phoenix_base_project(\""+projectConfig.name+"\" \""+projectConfig.version+"\"\n";
92  body += "\t\t\""+projectConfig.description+"\"\n";
93  body += "\t\t\""+projectConfig.url+"\")\n\n";
94 
95  body += "pull_extra_module(\"PhoenixDataStream\" \"https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/PhoenixDataStream.git\")\n";
96  body += "pull_extra_module(\"PhoenixTypeStream\" \"https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/PhoenixTypeStream.git\")\n\n";
97 
98  body += "phoenix_include_directories(\n";
99  body += "\t${CMAKE_CURRENT_SOURCE_DIR}\n";
100  body += "\t${CMAKE_CURRENT_BINARY_DIR}\n";
101  body += "\t${CMAKE_CURRENT_SOURCE_DIR}/src\n";
102  body += ")\n\n";
103  body += "phoenix_create_find("+projectConfig.name+" "+projectConfig.name.toLower()+" "+baseConfigClassName+".h "" PhoenixDataStream PhoenixTypeStream)\n\n";
104  body += "add_subdirectory(src)\n\n";
105  body += "phoenix_tests()\n";
106 
107  return fileName.saveFileContent(body);
108 }
bool saveFileContent(const PString &content) const
Save a PString in a file.
Definition: PPath.cpp:395
PString getCMakeListsHeader()
Get the CMakeLists.txt header.
PString description
Description of the project.
PString url
Project url.
PString version
Project version.

References ProjectConfig::description, getCMakeListsHeader(), ProjectConfig::name, PPath::saveFileContent(), PString::toLower(), ProjectConfig::url, and ProjectConfig::version.

Referenced by project_generator().

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

◆ project_generator_cmakeListsSrc()

bool project_generator_cmakeListsSrc ( const PPath fileName,
const PString projectName,
const PString libName 
)

Create the CMakeLists.txt of the src directory.

Parameters
fileName: name of the file to be created
projectName: name of hte project
libName: name of the library to be created
Returns
true on success, false otherwise

Definition at line 45 of file project_generator.cpp.

45  {
46  PString body;
47  body += getCMakeListsHeader();
48 
49  body += "file(GLOB "+libName+"_SRC \"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp\")\n";
50  body += "phoenix_add_library("+libName+" ${"+libName+"_SRC})\n";
51  body += "target_link_libraries("+libName+" phoenix_type_stream phoenix_data_stream)\n";
52 
53  body += "install(TARGETS "+libName+" LIBRARY DESTINATION ${LIBRARY_DIRECTORY} ARCHIVE DESTINATION ${LIBRARY_DIRECTORY})\n";
54 
55  body += "file(GLOB headers \"${CMAKE_CURRENT_SOURCE_DIR}/*.h\")\n";
56 
57  body += "install(FILES ${headers} DESTINATION include/"+projectName+")\n";
58 
59  return fileName.saveFileContent(body);
60 }

References getCMakeListsHeader(), and PPath::saveFileContent().

Referenced by project_generator().

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

◆ project_generator_cmakeListsTest()

bool project_generator_cmakeListsTest ( const PPath fileName,
const PString baseConfigClassName 
)

Create the main CMakeLists.txt of the project directory.

Parameters
fileName: name of the file to be created
baseConfigClassName: base name of the config class file
Returns
true on success, false otherwise

Definition at line 67 of file project_generator.cpp.

67  {
68  PString body;
69  body += getCMakeListsHeader();
70 
71  body += "add_subdirectory(TEST_"+baseConfigClassName.toUpper()+")\n\n";
72 
73  return fileName.saveFileContent(body);
74 }
PString toUpper() const
Convert std::string in upper case.
Definition: PString.cpp:639

References getCMakeListsHeader(), PPath::saveFileContent(), and PString::toUpper().

Referenced by project_generator().

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

◆ project_generator_gitignore()

bool project_generator_gitignore ( const PPath fileName)

Create the .gitignore of the project.

Parameters
fileName: name of the file to be created
Returns
true on success, false otherwise

Definition at line 159 of file project_generator.cpp.

159  {
160  PString body;
161  body += "build\n";
162  body += "build2\n";
163  body += ".kdev4/\n";
164  body += "*.kdev4\n";
165  body += ".tmp_project/\n";
166  body += "tmp_project/\n\n";
167  return fileName.saveFileContent(body);
168 }

References PPath::saveFileContent().

Referenced by project_generator().

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

◆ project_generator_gitlabci()

bool project_generator_gitlabci ( const PPath fileName,
const ProjectConfig projectConfig 
)

Create the .gitlab-ci.yml of the project.

Parameters
fileName: name of the file to be created
projectConfig: config of the project
Returns
true on success, false otherwise

Definition at line 175 of file project_generator.cpp.

175  {
176  PString specificRunnerTag;
177  if(projectConfig.runnerTag != ""){
178  specificRunnerTag += " tags:\n";
179  specificRunnerTag += " - "+projectConfig.runnerTag+"\n";
180  }
181 
182  PString body;
183  body += "\n";
184  body += getCMakeListsHeader();
185  body += "\nstages:\n";
186  body += "- BuildTestinstall\n";
187  body += "- DocCoverage\n";
188  body += "- deploy\n\n";
189 
190  body += "dailyBuildMasterAll:\n";
191  body += " image: gitlab-registry.in2p3.fr/cta-lapp/phoenix_libs2/phoenixcmake/phoenix_cmake_ubuntu_2204:latest\n";
192  body += " stage: BuildTestinstall\n";
193  body += " script:\n";
194  body += " - export LD_LIBRARY_PATH=/usr/lib\n";
195  body += " - env\n";
196  body += " - mkdir -p build\n";
197  body += " - cd build\n";
198  body += " - >\n";
199  body += " cmake ..\n";
200  body += " -DCMAKE_INSTALL_PREFIX=/usr\n";
201  body += " -DSELF_TESTS_MODE=yes\n";
202  body += " -DCMAKE_MODULE_PATH=/usr/share/cmake/Modules\n";
203  body += " - make all\n";
204  body += " - make install\n";
205  body += " - make test\n";
206  body += " only:\n";
207  body += " - branches\n";
208  body += " - tags\n";
209  body += specificRunnerTag;
210  body += "\n";
211 
212  body += "TestCoverage:\n";
213  body += " image: gitlab-registry.in2p3.fr/cta-lapp/phoenix_libs2/phoenixcmake/phoenix_cmake_ubuntu_2204:latest\n";
214  body += " stage: DocCoverage\n";
215  body += " script:\n";
216  body += " - export LD_LIBRARY_PATH=/usr/lib\n";
217  body += " - env\n";
218  body += " - mkdir -p build coverage\n";
219  body += " - cd build\n";
220  body += " - >\n";
221  body += " cmake ..\n";
222  body += " -DCMAKE_INSTALL_PREFIX=/usr\n";
223  body += " -DSELF_TESTS_MODE=yes\n";
224  body += " -DCMAKE_BUILD_TYPE=Coverage\n";
225  body += " -DCMAKE_MODULE_PATH=/usr/share/cmake/Modules\n";
226  body += " - make all\n";
227  body += " - make install\n";
228  body += " - make test\n";
229  body += " - ./uninstall_"+projectConfig.name.toLower()+"\n";
230  body += " - cd ../coverage\n";
231  body += " - gcovr -r ../ --exclude-throw-branches --html cov_report.html --html-details\n";
232  body += " - gcovr -r ../ --exclude-throw-branches --xml Coverage.xml\n";
233  body += " - gcovr -r ../ --exclude-throw-branches\n";
234  body += " coverage: '/TOTAL.*\\s+(\\d+\\%)$/'\n";
235  body += " artifacts:\n";
236  body += " paths:\n";
237  body += " - coverage\n";
238  body += " expire_in: 8d\n";
239  body += " only:\n";
240  body += " - branches\n";
241  body += " - tags\n";
242  body += specificRunnerTag;
243  body += "\n";
244  body += "Doc:\n";
245  body += " image: gitlab-registry.in2p3.fr/cta-lapp/phoenix_libs2/phoenixcmake/phoenix_cmake_ubuntu_2204:latest\n";
246  body += " stage: DocCoverage\n";
247  body += " script:\n";
248  body += " - export LD_LIBRARY_PATH=/usr/lib\n";
249  body += " - env\n";
250  body += " - rm -fr build public\n";
251  body += " - mkdir -p build\n";
252  body += " - mkdir -p public\n";
253  body += " - cd build\n";
254  body += " - >\n";
255  body += " cmake ..\n";
256  body += " -DCMAKE_INSTALL_PREFIX=/usr\n";
257  body += " -DDOC_MODE=yes\n";
258  body += " -DCMAKE_MODULE_PATH=/usr/share/cmake/Modules\n";
259  body += " - make all\n";
260  body += " - make doc\n";
261  body += " - scp -r doc/html/* ../public\n";
262  body += " artifacts:\n";
263  body += " paths:\n";
264  body += " - public\n";
265  body += " expire_in: 8d\n";
266  body += " only:\n";
267  body += " - branches\n";
268  body += " - tags\n";
269  body += specificRunnerTag;
270  body += "\n";
271  body += "pages:\n";
272  body += " stage: deploy\n";
273  body += " image: gitlab-registry.in2p3.fr/cta-lapp/phoenix_libs2/phoenixcmake/phoenix_cmake_ubuntu_2204:latest\n";
274  body += " script:\n";
275  body += " - mv coverage public/\n";
276  body += " artifacts:\n";
277  body += " paths:\n";
278  body += " - public\n";
279  body += " expire_in: 8d\n";
280  body += specificRunnerTag;
281  body += "\n";
282 
283  return fileName.saveFileContent(body);
284 }
PString runnerTag
Specific runner tag if needed (could be MUST_big_runner)

References getCMakeListsHeader(), ProjectConfig::name, ProjectConfig::runnerTag, PPath::saveFileContent(), and PString::toLower().

Referenced by project_generator().

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

◆ 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 18 of file project_generator.cpp.

18  {
19  DicoValue dico;
20  if(!parser_toml(dico, descriptionFile)){
21  std::cerr << "project_generator : cannot parse config file '"<<descriptionFile<<"'" << std::endl;
22  return false;
23  }
24  DicoValue * mapProject = dico.getMap("project");
25  if(mapProject == NULL){
26  std::cerr << "project_generator_loadConfig : Missing [project] in config file '"<<descriptionFile<<"'" << std::endl;
27  return false;
28  }
29  //TODO : It should be better to tell if there are missing values, but it's late ...
30  config.name = phoenix_get_string(*mapProject, "name", "MyAwesomeProject");
31  config.url = phoenix_get_string(*mapProject, "url", "need and url");
32  config.version = phoenix_get_string(*mapProject, "version", "0.0.1");
33  config.description = phoenix_get_string(*mapProject, "description", "A very important project");
34  config.mainBranch = phoenix_get_string(*mapProject, "main_branch", "master");
35  config.runnerTag = phoenix_get_string(*mapProject, "runner_tag", ""); //Could be MUST_big_runner
36  return true;
37 }
Dictionnary of values.
Definition: DicoValue.h:17
const DicoValue * getMap(const PString &key) const
Get a DicoValue in the map of the current one.
Definition: DicoValue.cpp:116
bool parser_toml(DicoValue &dico, const PPath &fileName)
PString phoenix_get_string(const DicoValue &dico, const PString &varName, const PString &defaultValue)
Get the string from a dictionnary.
PString mainBranch
Main branch of hte project.

References ProjectConfig::description, DicoValue::getMap(), ProjectConfig::mainBranch, ProjectConfig::name, parser_toml(), phoenix_get_string(), ProjectConfig::runnerTag, ProjectConfig::url, and ProjectConfig::version.

Referenced by project_generator().

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

◆ project_generator_readme()

bool project_generator_readme ( const PPath fileName,
const ProjectConfig projectConfig 
)

Create the readme of the project directory.

Parameters
fileName: name of the file to be created
projectConfig: config of the project
Returns
true on success, false otherwise

Definition at line 115 of file project_generator.cpp.

115  {
116  PString body, mainBranch(projectConfig.mainBranch);
117  body += "![PLIBS_9 logo](doc/logo.png)\n\n";
118 
119  body += "----\n";
120  body += "[![pipeline status]("+projectConfig.url+"/badges/"+mainBranch+"/pipeline.svg)]("+projectConfig.url+"/-/commits/"+mainBranch+")\n";
121  body += "[![coverage report]("+projectConfig.url+"/badges/"+mainBranch+"/coverage.svg)]("+projectConfig.url+"/-/commits/"+mainBranch+")\n\n";
122 
123  body += "# Remarks\n\n";
124  body += "This project was generated automatically by [phoenix_filegenerator](https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/PhoenixFileGenerator)\n";
125  body += "using [phoenix_generator](https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/PhoenixGenerator) library\n\n";
126 
127  body += "# Code\n\n";
128  body += "Version : " + projectConfig.version + "\n\n";
129  body += projectConfig.url + "\n\n";
130  body += "# Description\n\n";
131  body += projectConfig.description + "\n\n";
132 
133  PString docPagesUrl = getGitlabDocUrl(projectConfig.url);
134  if(docPagesUrl != ""){
135  body += "# Documentation\n\n";
136  body += "[See the pages documentation](" + docPagesUrl + ")\n\n";
137  }
138  body += "# Requirements\n\n";
139  body += "- c++ compiler (tested with g++ 11,12 and clang 14)\n";
140  body += "- [PhoenixCMake](https://gitlab.in2p3.fr/CTA-LAPP/PHOENIX_LIBS2/PhoenixCMake)\n";
141  body += "- cmake > 3\n";
142  body += "- make\n\n";
143 
144  body += "# Installation for Users\n\n";
145 
146  body += "```sh\n";
147  body += "git clone "+projectConfig.url+".git\n";
148  body += "cd "+projectConfig.name+"\n";
149  body += "./install.sh\n";
150  body += "```\n\n";
151 
152  return fileName.saveFileContent(body);
153 }
PString getGitlabDocUrl(const PString &projectUrl)
Get the documentation url of the given project url if possible.
Definition: gitlab_doc.cpp:14

References ProjectConfig::description, getGitlabDocUrl(), ProjectConfig::mainBranch, ProjectConfig::name, PPath::saveFileContent(), ProjectConfig::url, and ProjectConfig::version.

Referenced by project_generator().

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