25 #include <SimoxUtility/algorithm/string.h>
31 int main(
int argc,
char* argv[])
33 auto parseDeps = [](std::string
const & dependencies)
36 std::map<std::string, std::string> depsMap;
37 for (
auto& pairStr : depSplit)
43 ARMARX_WARNING <<
"Dependency '" << pair.at(0) <<
"' without path!";
46 depsMap[pair[0]] = pair[1];
51 auto getPackageNameFromPackagePath = [](std::string
const & packagePath )
53 namespace fs = std::filesystem;
55 std::optional<std::string>
ret;
57 auto source = fs::path(simox::alg::remove_suffix(packagePath,
"/")).parent_path() /
"source";
58 for (
const auto& f : fs::directory_iterator(
source))
60 if (fs::is_directory(f))
62 ret = std::make_optional(std::string(f.path().filename()));
69 if (argc == 5 && std::string(argv[1]) ==
"context")
71 ARMARX_DEBUG <<
"Generating statechart context header file.";
73 std::string statechartGroupXmlFilePath(argv[2]);
74 std::string packagePath(argv[3]);
75 const std::string packageIncludePath(argv[4]);
84 else if (argc == 4 && std::string(argv[1]) ==
"context")
86 ARMARX_DEBUG <<
"Generating statechart context header file (legacy mode).";
88 std::string statechartGroupXmlFilePath(argv[2]);
89 std::string packagePath(argv[3]);
99 else if (argc == 8 && std::string(argv[1]) ==
"package-cmake")
101 ARMARX_DEBUG <<
"Generating statechart CMake package source file.";
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]);
118 else if (argc == 7 && std::string(argv[1]) ==
"package-cmake")
120 ARMARX_DEBUG <<
"Generating statechart CMake package source file (legacy mode).";
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;
138 else if (argc == 8 && std::string(argv[1]) ==
"cmake")
140 ARMARX_DEBUG <<
"Generating statechart CMake source file.";
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]);
158 else if (argc == 7 && std::string(argv[1]) ==
"cmake")
160 ARMARX_DEBUG <<
"Generating statechart CMake source file (legacy mode).";
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;
177 else if (argc == 5 && std::string(argv[1]).find(
".scgxml") != std::string::npos)
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]);
186 ARMARX_DEBUG <<
"packageIncludePath " << packageIncludePath;
194 else if (argc == 4 && std::string(argv[1]).find(
".scgxml") != std::string::npos)
198 ARMARX_DEBUG <<
"Generating state header file (legacy mode).";
200 std::string statechartGroupXmlFilePath(argv[1]);
201 std::string stateFile(argv[2]);
202 std::string packagePath(argv[3]);
204 packagePath = simox::alg::remove_suffix(packagePath,
"/");
206 const std::optional<std::string> pName = getPackageNameFromPackagePath(packagePath);
207 if (!pName.has_value())
209 ARMARX_DEBUG <<
"Could not extract the package name of " << packagePath;
212 const std::string packageName = pName.value();
213 const std::string& packageIncludePath = packageName;
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>) .");