Skip to content

Commit

Permalink
Merge pull request #381 from bkryza/add-support-for-compile-flags-txt
Browse files Browse the repository at this point in the history
Added support for compile_flags.txt (#380)
  • Loading branch information
bkryza authored Jan 24, 2025
2 parents 85c27b4 + 7548b5a commit 0f712f1
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ Installation instructions for `Linux`, `macos` and `Windows` can be found

`clang-uml` requires an up-to-date
[compile_commands.json](https://clang.llvm.org/docs/JSONCompilationDatabase.html)
file, containing the list of commands used for compiling the source code.
file, containing the list of commands used for compiling the source code
or alternatively a list of compilation flags in a file called
`compile_flags.txt`
(see [here](https://clang.llvm.org/docs/JSONCompilationDatabase.html#alternatives).

See [here](https://blog.bkryza.com/posts/compile-commands-json-gallery/)
See also [here](https://blog.bkryza.com/posts/compile-commands-json-gallery/)
for instructions on how to generate `compile_commands.json` using some of the
existing C++ build systems.

Expand Down
2 changes: 1 addition & 1 deletion src/common/generators/display_adapters.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ template <typename T> class display_name_adapter {
}
}

return n;
return util::condense_whitespace(n);
}

private:
Expand Down
5 changes: 3 additions & 2 deletions src/common/generators/generators.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void make_context_source_relative(
void find_translation_units_for_diagrams(
const std::vector<std::string> &diagram_names,
clanguml::config::config &config,
const std::vector<std::string> &compilation_database_files,
const compilation_database &compilation_database,
std::map<std::string, std::vector<std::string>> &translation_units_map)
{
for (const auto &[name, diagram] : config.diagrams) {
Expand All @@ -56,7 +56,8 @@ void find_translation_units_for_diagrams(
continue;

translation_units_map[name] =
diagram->glob_translation_units(compilation_database_files);
diagram->glob_translation_units(compilation_database.getAllFiles(),
compilation_database.is_fixed());

LOG_DBG("Found {} translation units for diagram '{}'",
translation_units_map.at(name).size(), name);
Expand Down
4 changes: 2 additions & 2 deletions src/common/generators/generators.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ constexpr bool generator_supports_diagram_type(
*
* @param diagram_names List of diagram names, applies to all if empty
* @param config Reference to config instance
* @param compilation_database_files List of files found in compilation database
* @param compilation_database Reference to a compilation database
* @param translation_units_map Resulting translation units map is stored here
*/
void find_translation_units_for_diagrams(
const std::vector<std::string> &diagram_names,
clanguml::config::config &config,
const std::vector<std::string> &compilation_database_files,
const compilation_database &compilation_database,
std::map<std::string, std::vector<std::string>> &translation_units_map);

/**
Expand Down
6 changes: 3 additions & 3 deletions src/config/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ bool inheritable_diagram_options::generate_fully_qualified_name() const
}

std::vector<std::string> diagram::glob_translation_units(
const std::vector<std::string> &compilation_database_files) const
const std::vector<std::string> &compilation_database_files,
bool is_fixed) const
{

// Make sure that the paths are in preferred format for a given platform
// before intersecting the matches with compliation database
std::vector<std::string> compilation_database_paths;
Expand Down Expand Up @@ -471,7 +471,7 @@ std::vector<std::string> diagram::glob_translation_units(
for (const auto &gm : glob_matches) {
std::filesystem::path gm_path{gm};
gm_path.make_preferred();
if (util::contains(compilation_database_paths, gm_path) ||
if (is_fixed || util::contains(compilation_database_paths, gm_path) ||
util::contains(compilation_database_files, gm)) {
result.emplace_back(gm_path.string());
}
Expand Down
3 changes: 2 additions & 1 deletion src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,8 @@ struct diagram : public inheritable_diagram_options {
* @return List of translation unit paths
*/
std::vector<std::string> glob_translation_units(
const std::vector<std::string> &compilation_database_files) const;
const std::vector<std::string> &compilation_database_files,
bool is_fixed = false) const;

/**
* @brief Make path relative to the `relative_to` config option
Expand Down
3 changes: 1 addition & 2 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ int main(int argc, const char *argv[])
// before scheduling tasks, because std::filesystem::current_path
// cannot be trusted with multiple threads
common::generators::find_translation_units_for_diagrams(
cli.diagram_names, cli.config, compilation_database_files,
translation_units_map);
cli.diagram_names, cli.config, *db, translation_units_map);

if (cli.progress) {
// llvm::errs() output stream mangles the stdout stream , we need
Expand Down

0 comments on commit 0f712f1

Please sign in to comment.