Refactored handling of relative paths (#213)
This commit is contained in:
@@ -724,7 +724,10 @@ paths_filter::paths_filter(filter_t type, const std::filesystem::path &root,
|
||||
|
||||
resolved_absolute_path.make_preferred();
|
||||
|
||||
paths_.emplace_back(resolved_absolute_path);
|
||||
LOG_DBG("Added path {} to paths_filter",
|
||||
resolved_absolute_path.string());
|
||||
|
||||
paths_.emplace_back(std::move(resolved_absolute_path));
|
||||
|
||||
match_successful = true;
|
||||
}
|
||||
@@ -738,8 +741,8 @@ paths_filter::paths_filter(filter_t type, const std::filesystem::path &root,
|
||||
|
||||
if (!match_successful)
|
||||
LOG_WARN("Paths filter pattern '{}' did not match "
|
||||
"any files...",
|
||||
path);
|
||||
"any files relative to '{}'",
|
||||
path, root_.string());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1059,8 +1062,7 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
if (auto p = path.get<std::string>(); p.has_value()) {
|
||||
std::filesystem::path dep_path{*p};
|
||||
if (dep_path.is_relative()) {
|
||||
dep_path = c.base_directory() / *p;
|
||||
dep_path = relative(dep_path, c.relative_to());
|
||||
dep_path = relative(*p, c.root_directory());
|
||||
}
|
||||
|
||||
dependants.emplace_back(
|
||||
@@ -1072,8 +1074,7 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
if (auto p = path.get<std::string>(); p.has_value()) {
|
||||
std::filesystem::path dep_path{*p};
|
||||
if (dep_path.is_relative()) {
|
||||
dep_path = c.base_directory() / *p;
|
||||
dep_path = relative(dep_path, c.relative_to());
|
||||
dep_path = relative(*p, c.root_directory());
|
||||
}
|
||||
|
||||
dependencies.emplace_back(
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace clanguml::common::visitor {
|
||||
translation_unit_visitor::translation_unit_visitor(
|
||||
clang::SourceManager &sm, const clanguml::config::diagram &config)
|
||||
: source_manager_{sm}
|
||||
, relative_to_path_{config.relative_to()}
|
||||
, relative_to_path_{config.root_directory()}
|
||||
{
|
||||
if (config.comment_parser() == config::comment_parser_t::plain) {
|
||||
comment_visitor_ =
|
||||
@@ -108,6 +108,8 @@ void translation_unit_visitor::set_source_location(
|
||||
const clang::SourceLocation &location,
|
||||
clanguml::common::model::source_location &element)
|
||||
{
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
std::string file;
|
||||
unsigned line{};
|
||||
unsigned column{};
|
||||
@@ -133,15 +135,25 @@ void translation_unit_visitor::set_source_location(
|
||||
}
|
||||
}
|
||||
|
||||
if (std::filesystem::path file_path{file}; !file_path.is_absolute()) {
|
||||
file_path =
|
||||
std::filesystem::canonical(std::filesystem::absolute(file_path));
|
||||
file = file_path.string();
|
||||
// ensure the path is absolute
|
||||
fs::path file_path{file};
|
||||
if (!file_path.is_absolute()) {
|
||||
file_path = fs::absolute(file_path);
|
||||
}
|
||||
|
||||
file_path = fs::canonical(file_path);
|
||||
|
||||
if (!util::is_relative_to(file_path, relative_to_path_)) {
|
||||
return;
|
||||
}
|
||||
|
||||
file = file_path.string();
|
||||
|
||||
element.set_file(file);
|
||||
element.set_file_relative(util::path_to_url(
|
||||
std::filesystem::relative(element.file(), relative_to_path_).string()));
|
||||
if (util::is_relative_to(file_path, relative_to_path_)) {
|
||||
element.set_file_relative(util::path_to_url(
|
||||
fs::relative(element.file(), relative_to_path_).string()));
|
||||
}
|
||||
element.set_translation_unit(tu_path().string());
|
||||
element.set_line(line);
|
||||
element.set_column(column);
|
||||
|
||||
Reference in New Issue
Block a user