diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.cpp index 77485c5fdb3b8ce814366b0b73492d249235ab5c..cf56e483356695bf2b54a747e36c4d758e7f1a56 100644 --- a/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.cpp +++ b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.cpp @@ -29,20 +29,38 @@ // ArmarX #include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h> +#include <ArmarXCore/core/system/cmake/CMakePackageFinder.h> #include <RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Data.h> #include <RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.h> + +namespace fs = std::filesystem; + namespace armarx::aron::xmltypereader { - void Reader::parseFile(const std::string& filename) + void Reader::parseFile(const std::string& _filename) { - RapidXmlReaderPtr reader = RapidXmlReader::FromFile(filename); - parse(reader); + std::string filename = _filename; + // Handle C++ style includes like "<path/to/file>". + if (!filename.empty() && filename.front() == '<' && filename.back() == '>') + { + filename = filename.substr(1, filename.size() - 2); + } + parseFile(std::filesystem::path(filename)); } - void Reader::parseFile(const std::filesystem::path& file) + void Reader::parseFile(const std::filesystem::path& _file) { + fs::path file = _file; + if (!file.empty() && file.is_relative()) + { + if (std::optional<fs::path> resolved = detail::resolveRelativePackagePath(file)) + { + file = resolved.value(); + } + } + RapidXmlReaderPtr reader = RapidXmlReader::FromFile(file.string()); parse(reader); } @@ -185,4 +203,30 @@ namespace armarx::aron::xmltypereader return typenavigator::IntEnumNavigator::DynamicCastAndCheck(factory.create(node, Path())); } + + + std::optional<fs::path> detail::resolveRelativePackagePath(const fs::path& path) + { + const std::string package = *path.begin(); + armarx::CMakePackageFinder finder(package); + if (finder.packageFound()) + { + for (const std::string& includePath : finder.getIncludePathList()) + { + fs::path absPath = includePath / path; + if (fs::is_regular_file(absPath)) + { + return absPath; + } + } + return std::nullopt; + } + else + { + return std::nullopt; + } + } + } + + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.h b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.h index 0801465160e06ddbd0ebfc78b57d8b8bb97eafcd..e19083a9aa2718792c705ec41267a4e7f50d2cc8 100644 --- a/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.h +++ b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.h @@ -24,8 +24,10 @@ #pragma once // STD/STL -#include <memory> #include <filesystem> +#include <memory> +#include <optional> + // Base Class #include <RobotAPI/libraries/aron/core/codegenerator/typeReader/Reader.h> @@ -63,4 +65,10 @@ namespace armarx::aron::xmltypereader private: ReaderFactory factory; }; + + + namespace detail + { + std::optional<std::filesystem::path> resolveRelativePackagePath(const std::filesystem::path& path); + } } diff --git a/source/RobotAPI/libraries/aron/core/test/CMakeLists.txt b/source/RobotAPI/libraries/aron/core/test/CMakeLists.txt index 7eeffdbb49db4b321b77ed47fa1e58361d538094..de44d5a1d28a8148139265d1a18a6667c1c4a697 100644 --- a/source/RobotAPI/libraries/aron/core/test/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/core/test/CMakeLists.txt @@ -40,20 +40,22 @@ armarx_enable_aron_file_generation_for_target( TARGET_NAME ${TEST_NAME} ARON_FILES - xmls/HumanPoseTest.xml + # xmls/BaseClass.xml + # xmls/DerivedClassTest.xml xmls/DictTest.xml + xmls/EigenMatrixTest.xml + xmls/EigenQuaternionTest.xml + xmls/EnumTest.xml + xmls/HumanPoseTest.xml + xmls/IVTCByteImageTest.xml xmls/ListTest.xml xmls/NaturalIKTest.xml xmls/ObjectTest.xml - xmls/PrimitiveTest.xml - xmls/IVTCByteImageTest.xml - xmls/EigenMatrixTest.xml - xmls/EigenQuaternionTest.xml xmls/OpenCVMatTest.xml - xmls/PCLPointCloudTest.xml - xmls/PositionTest.xml xmls/OrientationTest.xml + xmls/PCLPointCloudTest.xml xmls/PoseTest.xml - xmls/EnumTest.xml + xmls/PositionTest.xml + xmls/PrimitiveTest.xml #ENABLE_DEBUG_INFO )