132{
133
134 if (diagrams.empty()) return;
135
138 {
139 mmdc += "/";
140 }
141 mmdc += "mmdc";
142
144
145 struct MermaidCmd
146 {
147 MermaidCmd(const QCString &mmdc_,const QCString &args_,const QCString &ext_,const QCString &srcFile_,int srcLine_) :
148 mmdc(mmdc_), args(args_), ext(ext_), srcFile(srcFile_), srcLine(srcLine_) {}
149 QCString mmdc;
150 QCString args;
151 QCString ext;
152 QCString srcFile;
153 int srcLine;
154 };
155 std::vector<MermaidCmd> mermaidCmds;
156
157 for (const auto &diagram : diagrams)
158 {
159
160 if (diagram.info.content.isEmpty()) continue;
161
163
164 QCString inputFile = diagram.info.baseName +
".mmd";
165 QCString outputFile = diagram.info.baseName +
"." + ext;
166
167
169 if (fi.exists())
170 {
172 if (cachedContent == diagram.info.content)
173 {
174 continue;
175 }
176 }
177
178
180 args += "-q -i \"" + inputFile + "\" ";
181 args += "-o \"" + outputFile + "\" ";
182
183 if (!mermaidConfigFile.
isEmpty())
184 {
185 args += "-c \"" + mermaidConfigFile + "\" ";
186 }
187
188 mermaidCmds.emplace_back(mmdc, args,ext, diagram.info.srcFile, diagram.info.srcLine);
189 }
190
191 std::size_t numThreads =
static_cast<std::size_t
>(
Config_getInt(DOT_NUM_THREADS));
192 size_t offset=0;
193 size_t total=mermaidCmds.size();
194 msg(
"Generating {} Mermaid files using {} threads\n", total, numThreads);
195 if (numThreads>1)
196 {
198 std::vector< std::future<int> > results;
199
200
201 for (const auto &cmd : mermaidCmds)
202 {
203 auto processFile = [&cmd]()
204 {
207 if (exitCode != 0)
208 {
210 "Problems running Mermaid (mmdc). Verify that the command '{} {}' works from the command line. Exit code: {}.",
211 cmd.mmdc, cmd.args, exitCode);
212 }
213 return exitCode;
214 };
215 results.emplace_back(threadPool.queue(processFile));
216 }
217
218
219 for (auto &f : results)
220 {
221 offset++;
222 msg(
"Generating Mermaid file {}/{}\n", offset, total);
223 f.get();
224 }
225 }
226 else
227 {
228 for (const auto &cmd : mermaidCmds)
229 {
230 offset++;
231 msg(
"Generating Mermaid file {}/{}\n", offset, total);
233
235 if (exitCode != 0)
236 {
238 "Problems running Mermaid (mmdc). Verify that the command '{} {}' works from the command line. Exit code: {}.",
239 cmd.mmdc, cmd.args, exitCode);
240 }
241 }
242 }
243}
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Minimal replacement for QFileInfo.
static QCString imageExtension(ImageFormat imageFormat)
This is an alternative implementation of QCString.
size_t length() const
Returns the length of the string, not counting the 0-terminator.
char & at(size_t i)
Returns a reference to the character at index i.
bool isEmpty() const
Returns TRUE iff the string is empty.
const std::string & str() const
Class managing a pool of worker threads.
#define Config_getInt(name)
#define Config_getString(name)
#define err_full(file, line, fmt,...)
int system(const QCString &command, const QCString &args, bool commandHasConsole=true)
QCString fileToString(const QCString &name, bool filter, bool isSourceCode)