Refactored handling of relative paths (#213)

This commit is contained in:
Bartek Kryza
2023-12-08 08:17:00 +01:00
parent f1d3695ccc
commit d7195d5a5d
130 changed files with 317 additions and 255 deletions

View File

@@ -233,8 +233,7 @@ std::vector<std::string> diagram::get_translation_units() const
{
std::vector<std::string> translation_units{};
LOG_DBG("Looking for translation units in {}",
std::filesystem::current_path().string());
LOG_DBG("Looking for translation units in {}", root_directory().string());
for (const auto &g : glob()) {
std::string glob_path =

View File

@@ -482,10 +482,6 @@ struct inheritable_diagram_options {
// This is the absolute filesystem path to the directory containing
// the current .clang-uml config file - it is set automatically
option<std::filesystem::path> base_directory{"__parent_path"};
// This is the relative path with respect to the `base_directory`,
// against which all matches are made, if not provided it defaults to
// the `base_directory`
option<std::filesystem::path> relative_to{"relative_to"};
option<bool> generate_system_headers{"generate_system_headers", false};
option<relationship_hints_t> relationship_hints{"relationship_hints"};
option<type_aliases_t> type_aliases{"type_aliases"};
@@ -502,6 +498,30 @@ struct inheritable_diagram_options {
"message_comment_width", clanguml::util::kDefaultMessageCommentWidth};
option<bool> debug_mode{"debug_mode", false};
option<bool> generate_metadata{"generate_metadata", true};
/**
* @brief Get reference to `relative_to` diagram config option
*
* This method is only to allow access to `relative_to` for loading
* and adjusting configuration file and for making test cases work.
*
* Instead use @see config::diagram::root_directory() method.
*
* @return Reference to `relative_to` config option.
*/
option<std::filesystem::path> &get_relative_to() { return relative_to; }
protected:
// This is the relative path with respect to the `base_directory`,
// against which all matches are made, if not provided it defaults to
// the `base_directory`
//
// This option should not be accessed directly in code - instead use
// @see config::diagram::root_directory()
option<std::filesystem::path> relative_to{"relative_to"};
friend YAML::Emitter &operator<<(
YAML::Emitter &out, const inheritable_diagram_options &c);
};
/**

View File

@@ -602,7 +602,7 @@ template <> struct convert<class_diagram> {
get_option(node, rhs.skip_redundant_dependencies);
get_option(node, rhs.relationship_hints);
get_option(node, rhs.type_aliases);
get_option(node, rhs.relative_to);
get_option(node, rhs.get_relative_to());
rhs.initialize_relationship_hints();
rhs.initialize_type_aliases();
@@ -626,15 +626,15 @@ template <> struct convert<sequence_diagram> {
get_option(node, rhs.combine_free_functions_into_file_participants);
get_option(node, rhs.generate_return_types);
get_option(node, rhs.generate_condition_statements);
get_option(node, rhs.relative_to);
get_option(node, rhs.get_relative_to());
get_option(node, rhs.participants_order);
get_option(node, rhs.generate_method_arguments);
get_option(node, rhs.generate_message_comments);
get_option(node, rhs.message_comment_width);
// Ensure relative_to has a value
if (!rhs.relative_to.has_value)
rhs.relative_to.set(
if (!rhs.get_relative_to().has_value)
rhs.get_relative_to().set(
std::filesystem::current_path().lexically_normal());
rhs.initialize_type_aliases();
@@ -653,12 +653,12 @@ template <> struct convert<package_diagram> {
return false;
get_option(node, rhs.layout);
get_option(node, rhs.relative_to);
get_option(node, rhs.get_relative_to());
get_option(node, rhs.package_type);
// Ensure relative_to has a value
if (!rhs.relative_to.has_value)
rhs.relative_to.set(
if (!rhs.get_relative_to().has_value)
rhs.get_relative_to().set(
std::filesystem::current_path().lexically_normal());
return true;
@@ -675,21 +675,12 @@ template <> struct convert<include_diagram> {
return false;
get_option(node, rhs.layout);
get_option(node, rhs.relative_to);
get_option(node, rhs.get_relative_to());
get_option(node, rhs.generate_system_headers);
if (!rhs.relative_to)
rhs.relative_to.set(std::filesystem::current_path());
// Convert the path in relative_to to an absolute path, with respect
// to the directory where the `.clang-uml` configuration file is
// located
if (rhs.relative_to) {
auto absolute_relative_to =
std::filesystem::path{node["__parent_path"].as<std::string>()} /
rhs.relative_to();
rhs.relative_to.set(absolute_relative_to.lexically_normal());
}
if (!rhs.get_relative_to().has_value)
rhs.get_relative_to().set(
std::filesystem::current_path().lexically_normal());
return true;
}
@@ -824,7 +815,7 @@ template <> struct convert<config> {
get_option(node, rhs.message_comment_width);
rhs.base_directory.set(node["__parent_path"].as<std::string>());
get_option(node, rhs.relative_to);
get_option(node, rhs.get_relative_to());
get_option(node, rhs.diagram_templates);