0.6.1
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Functions
main.cc File Reference
#include "cli/cli_handler.h"
#include "common/compilation_database.h"
#include "common/generators/generators.h"
#include "util/query_driver_output_extractor.h"
#include "util/util.h"
#include <cli11/CLI11.hpp>
#include <spdlog/spdlog.h>
#include <cstring>

Go to the source code of this file.

Functions

int main (int argc, const char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Definition at line 44 of file main.cc.

45{
47
48 try {
49 auto res = cli.handle_options(argc, argv);
50
51 if (res == cli::cli_flow_t::kExit)
52 return 0;
53
54 if (res == cli::cli_flow_t::kError)
55 return 1;
56
57#if !defined(NDEBUG)
58 // Catch invalid logger message formats, e.g. missing arguments
59 spdlog::set_error_handler([](const std::string & /*msg*/) {
60 assert(0 == 1); // NOLINT
61 });
62#endif
63
64 const auto db =
66 cli.config);
67
68 const auto compilation_database_files = db->getAllFiles();
69
70 std::map<std::string /* diagram name */,
71 std::vector<std::string> /* translation units */>
72 translation_units_map;
73
74 // We have to generate the translation units list for each diagram
75 // before scheduling tasks, because std::filesystem::current_path
76 // cannot be trusted with multiple threads
78 cli.diagram_names, cli.config, *db, translation_units_map);
79
80 if (cli.progress) {
81 // llvm::errs() output stream mangles the stdout stream , we need
82 // to close it here so that it doesn't interfere with the rendering
83 // of progress indicators
84 llvm::errs().close();
85 }
86
88 cli.config, db, cli.get_runtime_config(), translation_units_map);
89 }
91 if (clanguml::logging::logger_type() == logging::logger_type_t::text) {
92 fmt::println(
93 "ERROR: Failed to load compilation database from {} due to: {}",
94 cli.config.compilation_database_dir(), e.what());
95 }
96 else {
97 LOG_ERROR("Failed to load compilation database from {} due to: {}",
98 cli.config.compilation_database_dir(), e.what());
99 }
100 return 1;
101 }
103 if (clanguml::logging::logger_type() == logging::logger_type_t::text) {
104 fmt::println(
105 "ERROR: Querying provided compiler driver {} did not provide "
106 "any "
107 "paths, please make sure the path is correct and that your "
108 "compiler is GCC-compatible: {}",
109 cli.config.query_driver(), e.what());
110 }
111 else {
112 LOG_ERROR(
113 "Querying provided compiler driver {} did not provide any "
114 "paths, please make sure the path is correct and that your "
115 "compiler is GCC-compatible: {}",
116 cli.config.query_driver(), e.what());
117 }
118 return 1;
119 }
121 if (clanguml::logging::logger_type() == logging::logger_type_t::text)
122 fmt::println("ERROR: {}", e.what());
123 else
124 LOG_ERROR("{}", e.what());
125 return 1;
126 }
127 catch (std::exception &e) {
128 if (clanguml::logging::logger_type() == logging::logger_type_t::text)
129 fmt::println("ERROR: {}", e.what());
130 else
131 LOG_ERROR("{}", e.what());
132 return 1;
133 }
134
135 return 0;
136}