diff options
author | Roland Reichwein <mail@reichwein.it> | 2024-05-07 19:08:29 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2024-05-07 19:08:29 +0200 |
commit | 7dabda20e11138f2235b12271d569cd3256ebf3a (patch) | |
tree | d917df1ea84609519a560a092a63683cb54b1894 /MakefileReader.cpp | |
parent | 81bcfee54362c736e865ebeb638aeadfa9cc9e24 (diff) |
Recursive build
Diffstat (limited to 'MakefileReader.cpp')
-rw-r--r-- | MakefileReader.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/MakefileReader.cpp b/MakefileReader.cpp new file mode 100644 index 0000000..ebcc0a8 --- /dev/null +++ b/MakefileReader.cpp @@ -0,0 +1,64 @@ +#include "MakefileReader.h" + +#include <boost/property_tree/xml_parser.hpp> + +#include "file.h" + +namespace pt = boost::property_tree; +namespace fs = std::filesystem; + +namespace { + // the elements with this name are considered paths, where relative prefixes will be added if necessary + std::vector<std::string> path_elements{"name", "source", "test"}; + + // add path to respective elements in tree, recursively + void adjust_path(pt::ptree::value_type& element, const fs::path& path) { + // add path prefix if path element + if (std::find(path_elements.begin(), path_elements.end(), element.first) != path_elements.end()) { + std::string content{element.second.data()}; + element.second.data() = simplified_path(path / fs::path{content}).string(); + } + + for (auto &i: element.second) { + // recursively run + adjust_path(i, path); + } + } + + void join(pt::ptree& tree, const pt::ptree& makefile_tree, const fs::path& path) { + if (tree.empty()) { + tree = makefile_tree; // including top level single "ymake" element + } else { + // copy all elements inside single "ymake" + pt::ptree& target{tree.get_child("ymake")}; + const pt::ptree& source{makefile_tree.get_child("ymake")}; + for (const auto& i: source) { + auto it {target.push_back(i)}; + auto &element{*it}; + adjust_path(element, path); + } + } + } +} + +MakefileReader::MakefileReader() +{ +} + +pt::ptree MakefileReader::read(const fs::path& path) const +{ + pt::ptree ptree; + + for (const fs::directory_entry& dir_entry: fs::recursive_directory_iterator(path)) { + pt::ptree makefile_tree; + fs::path path{dir_entry.path()}; + + if (dir_entry.is_regular_file() && path.filename() == YMakefile) { + pt::read_xml(path, makefile_tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); + + join(ptree, makefile_tree, simplified_path(path.parent_path())); + } + } + + return ptree; +} |