main.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package Core::application::StatechartGroupDocGenerator
19  * @author Mirko Waechter
20  * @date 2014
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include <SimoxUtility/algorithm/string.h>
26 
30 
31 int main(int argc, char* argv[])
32 {
33  auto parseDeps = [](std::string const & dependencies)
34  {
35  auto depSplit = armarx::Split(dependencies, ";", true, true);
36  std::map<std::string, std::string> depsMap;
37  for (auto& pairStr : depSplit)
38  {
39  auto pair = armarx::Split(pairStr, ":", true, true);
40 
41  if(pair.size() != 2)
42  {
43  ARMARX_WARNING << "Dependency '" << pair.at(0) << "' without path!";
44  continue;
45  }
46  depsMap[pair[0]] = pair[1];
47  }
48  return depsMap;
49  };
50 
51  auto getPackageNameFromPackagePath = [](std::string const & packagePath /* path to <PackageName>/build */)
52  {
53  namespace fs = std::filesystem;
54 
55  std::optional<std::string> ret;
56 
57  auto source = fs::path(simox::alg::remove_suffix(packagePath, "/")).parent_path() / "source";
58  for (const auto& f : fs::directory_iterator(source))
59  {
60  if (fs::is_directory(f))
61  {
62  ret = std::make_optional(std::string(f.path().filename()));
63  break;
64  }
65  }
66  return ret;
67  };
68 
69  if (argc == 5 && std::string(argv[1]) == "context")
70  {
71  ARMARX_DEBUG << "Generating statechart context header file.";
72 
73  std::string statechartGroupXmlFilePath(argv[2]);
74  std::string packagePath(argv[3]);
75  const std::string packageIncludePath(argv[4]);
76 
77  if(armarx::StatechartGroupGenerator::generateStatechartContextFile(statechartGroupXmlFilePath, packagePath, packageIncludePath))
78  {
79  return EXIT_SUCCESS;
80  }
81 
82  return EXIT_FAILURE;
83  }
84  else if (argc == 4 && std::string(argv[1]) == "context") // legacy
85  {
86  ARMARX_DEBUG << "Generating statechart context header file (legacy mode).";
87 
88  std::string statechartGroupXmlFilePath(argv[2]);
89  std::string packagePath(argv[3]);
90 
91  if(armarx::StatechartGroupGenerator::generateStatechartContextFile(statechartGroupXmlFilePath, packagePath, std::nullopt))
92  {
93  return EXIT_SUCCESS;
94  }
95 
96  ARMARX_WARNING << "Failure";
97  return EXIT_FAILURE;
98  }
99  else if (argc == 8 && std::string(argv[1]) == "package-cmake")
100  {
101  ARMARX_DEBUG << "Generating statechart CMake package source file.";
102 
103  std::string packageName(argv[2]);
104  std::string statechartsDir(argv[3]);
105  std::string buildDir(argv[4]);
106  std::string dataDir(argv[5]);
107  std::string dependencies(argv[6]);
108  auto depsMap = parseDeps(dependencies);
109  const std::string packageIncludePath(argv[7]);
110 
111  if(armarx::StatechartGroupGenerator::generateStatechartGroupCMakeSourceListFiles(packageName, statechartsDir, buildDir, false, dataDir, depsMap, packageIncludePath, true))
112  {
113  return EXIT_SUCCESS;
114  }
115 
116  return EXIT_FAILURE;
117  }
118  else if (argc == 7 && std::string(argv[1]) == "package-cmake") // legacy
119  {
120  ARMARX_DEBUG << "Generating statechart CMake package source file (legacy mode).";
121 
122  std::string packageName(argv[2]);
123  std::string statechartsDir(argv[3]);
124  std::string buildDir(argv[4]);
125  std::string dataDir(argv[5]);
126  std::string dependencies(argv[6]);
127  auto depsMap = parseDeps(dependencies);
128  const std::string& packageIncludePath = packageName;
129 
130  if(armarx::StatechartGroupGenerator::generateStatechartGroupCMakeSourceListFiles(packageName, statechartsDir, buildDir, false, dataDir, depsMap, packageIncludePath))
131  {
132  return EXIT_SUCCESS;
133  }
134 
135  return EXIT_FAILURE;
136 
137  }
138  else if (argc == 8 && std::string(argv[1]) == "cmake")
139  {
140  ARMARX_DEBUG << "Generating statechart CMake source file.";
141 
142  std::string packageName(argv[2]);
143  std::string statechartGroupXmlFilePath(argv[3]);
144  std::string buildDir(argv[4]);
145  std::string dataDir(argv[5]);
146  std::string dependencies(argv[6]);
147  auto depsMap = parseDeps(dependencies);
148  const std::string packageIncludePath(argv[7]);
149 
150  if(armarx::StatechartGroupGenerator::generateStatechartGroupCMakeSourceListFile(packageName, statechartGroupXmlFilePath, buildDir, false, dataDir, depsMap, packageIncludePath, true))
151  {
152  return EXIT_SUCCESS;
153  }
154 
155  return EXIT_FAILURE;
156 
157  }
158  else if (argc == 7 && std::string(argv[1]) == "cmake") // legacy
159  {
160  ARMARX_DEBUG << "Generating statechart CMake source file (legacy mode).";
161 
162  std::string packageName(argv[2]);
163  std::string statechartGroupXmlFilePath(argv[3]);
164  std::string buildDir(argv[4]);
165  std::string dataDir(argv[5]);
166  std::string dependencies(argv[6]);
167  auto depsMap = parseDeps(dependencies);
168  const std::string& packageIncludePath = packageName;
169 
170  if(armarx::StatechartGroupGenerator::generateStatechartGroupCMakeSourceListFile(packageName, statechartGroupXmlFilePath, buildDir, false, dataDir, depsMap, packageIncludePath))
171  {
172  return EXIT_SUCCESS;
173  }
174 
175  return EXIT_FAILURE;
176  }
177  else if (argc == 5 && std::string(argv[1]).find(".scgxml") != std::string::npos)
178  {
179  ARMARX_DEBUG << "Generating state header file.";
180 
181  std::string statechartGroupXmlFilePath(argv[1]);
182  std::string stateFile(argv[2]);
183  std::string packagePath(argv[3]);
184  const std::string packageIncludePath(argv[4]);
185 
186  ARMARX_DEBUG << "packageIncludePath " << packageIncludePath;
187  if(armarx::StatechartGroupGenerator::generateStateFile(statechartGroupXmlFilePath, stateFile, packagePath, packageIncludePath))
188  {
189  return EXIT_SUCCESS;
190  }
191 
192  return EXIT_FAILURE;
193  }
194  else if (argc == 4 && std::string(argv[1]).find(".scgxml") != std::string::npos) // legacy
195  {
196  ARMARX_TRACE;
197 
198  ARMARX_DEBUG << "Generating state header file (legacy mode).";
199 
200  std::string statechartGroupXmlFilePath(argv[1]);
201  std::string stateFile(argv[2]);
202  std::string packagePath(argv[3]);
203 
204  packagePath = simox::alg::remove_suffix(packagePath, "/");
205 
206  const std::optional<std::string> pName = getPackageNameFromPackagePath(packagePath);
207  if (!pName.has_value())
208  {
209  ARMARX_DEBUG << "Could not extract the package name of " << packagePath;
210  }
211 
212  const std::string packageName = pName.value(); //getPackageNameFromPackagePath(packagePath);
213  const std::string& packageIncludePath = packageName;
214 
215  if(armarx::StatechartGroupGenerator::generateStateFile(statechartGroupXmlFilePath, stateFile, packagePath, packageIncludePath))
216  {
217  return EXIT_SUCCESS;
218  }
219 
220  return EXIT_FAILURE;
221  }
222  else
223  {
224  throw armarx::LocalException("Incorrect parameters. Expected: (<Statechartgroupfile.scgxml> <statefile.xml> <packagePath> "
225  "| context <Statechartgroupfile.scgxml> <packagePath> "
226  "| cmake <PackageName> <Statechartgroupfile.scgxml> <builddir> <datadir> <dependenciesWithPaths>"
227  "| package-cmake <PackageName> <StatechartDir> <builddir> <datadir> <dependenciesWithPaths>) .");
228  }
229 
230  return EXIT_FAILURE;
231 }
armarx::StatechartGroupGenerator::generateStatechartContextFile
static bool generateStatechartContextFile(const std::string &statechartGroupXmlFilePath, const std::string &packagePath, const std::optional< std::string > &packageIncludePath=std::nullopt)
Definition: StateGroupGenerator.cpp:134
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
armarx::StatechartGroupGenerator::generateStateFile
static bool generateStateFile(const std::string &statechartGroupXmlFilePath, const std::string &statePath, const std::string &packagePath, const std::optional< std::string > &packageIncludePath=std::nullopt)
Definition: StateGroupGenerator.cpp:61
armarx::Split
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelperTemplates.h:35
armarx::StatechartGroupGenerator::generateStatechartGroupCMakeSourceListFiles
static bool generateStatechartGroupCMakeSourceListFiles(const std::string &packageName, const std::string &statechartGroupXmlFilePath, const std::filesystem::path &buildDir, bool forceRewrite, const std::string &dataDir, const std::map< std::string, std::string > &dependencies, const std::optional< std::string > &packageIncludePath=std::nullopt, bool nextGenBehavior=false)
Definition: StateGroupGenerator.cpp:356
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
main
int main(int argc, char *argv[])
Definition: main.cpp:31
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
ExpressionException.h
armarx::StatechartGroupGenerator::generateStatechartGroupCMakeSourceListFile
static bool generateStatechartGroupCMakeSourceListFile(const std::string &statechartGroupXmlFilePath, const std::filesystem::path &buildDir, bool forceRewrite, const std::optional< std::string > &packageIncludePath=std::nullopt, bool nextGenBehavior=false)
Definition: StateGroupGenerator.cpp:346
StateGroupGenerator.h
Logging.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186