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