kde4automoc.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /*
  2. Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. 1. Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  12. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  13. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  14. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  15. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  16. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  17. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  18. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  20. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. */
  22. #include <QtCore/QCoreApplication>
  23. #include <QtCore/QDateTime>
  24. #include <QtCore/QFile>
  25. #include <QtCore/QFileInfo>
  26. #include <QtCore/QHash>
  27. #include <QtCore/QProcess>
  28. #include <QtCore/QQueue>
  29. #include <QtCore/QRegExp>
  30. #include <QtCore/QStringList>
  31. #include <QtCore/QTextStream>
  32. #include <QtCore/QtDebug>
  33. #include <cstdlib>
  34. #include <sys/types.h>
  35. #include <time.h>
  36. #include <errno.h>
  37. #ifdef Q_OS_WIN
  38. #include <windows.h>
  39. #include <sys/utime.h>
  40. #else
  41. #include <utime.h>
  42. #endif
  43. // currently this is only used for the version number, Alex
  44. #include "automoc4_config.h"
  45. class AutoMoc
  46. {
  47. public:
  48. AutoMoc();
  49. bool run();
  50. private:
  51. void dotFilesCheck(bool);
  52. void lazyInit();
  53. bool touch(const QString &filename);
  54. bool generateMoc(const QString &sourceFile, const QString &mocFileName);
  55. void waitForProcesses();
  56. void printUsage(const QString &);
  57. void printVersion();
  58. void echoColor(const QString &msg)
  59. {
  60. QProcess *cmakeEcho = new QProcess;
  61. cmakeEcho->setProcessChannelMode(QProcess::ForwardedChannels);
  62. QStringList args(cmakeEchoColorArgs);
  63. args << msg;
  64. cmakeEcho->start(cmakeExecutable, args, QIODevice::NotOpen);
  65. processes.enqueue(Process(cmakeEcho, QString()));
  66. }
  67. QString builddir;
  68. QString mocExe;
  69. QStringList mocIncludes;
  70. QStringList mocDefinitions;
  71. QStringList cmakeEchoColorArgs;
  72. QString cmakeExecutable;
  73. QFile dotFiles;
  74. const bool verbose;
  75. QTextStream cerr;
  76. QTextStream cout;
  77. struct Process
  78. {
  79. Process(QProcess *a, const QString &b) : qproc(a), mocFilePath(b) {}
  80. QProcess *qproc;
  81. QString mocFilePath;
  82. };
  83. QQueue<Process> processes;
  84. bool failed;
  85. bool automocCppChanged;
  86. bool generateAll;
  87. bool doTouch;
  88. };
  89. void AutoMoc::printUsage(const QString &path)
  90. {
  91. cout << "Usage: " << path << " <outfile> <srcdir> <builddir> <moc executable> <cmake executable> [--touch]" << endl;
  92. }
  93. void AutoMoc::printVersion()
  94. {
  95. cout << "automoc4 " << AUTOMOC4_VERSION << endl;
  96. }
  97. void AutoMoc::dotFilesCheck(bool x)
  98. {
  99. if (!x) {
  100. cerr << "Error: syntax error in " << dotFiles.fileName() << endl;
  101. ::exit(EXIT_FAILURE);
  102. }
  103. }
  104. int main(int argc, char **argv)
  105. {
  106. QCoreApplication app(argc, argv);
  107. if (!AutoMoc().run()) {
  108. return EXIT_FAILURE;
  109. }
  110. return 0;
  111. }
  112. AutoMoc::AutoMoc()
  113. : verbose(!qgetenv("VERBOSE").isEmpty()), cerr(stderr), cout(stdout), failed(false),
  114. automocCppChanged(false), doTouch(false)
  115. {
  116. const QByteArray colorEnv = qgetenv("COLOR");
  117. cmakeEchoColorArgs << QLatin1String("-E") << QLatin1String("cmake_echo_color")
  118. << QLatin1String("--switch=") + colorEnv << QLatin1String("--blue")
  119. << QLatin1String("--bold");
  120. }
  121. void AutoMoc::lazyInit()
  122. {
  123. const QStringList &args = QCoreApplication::arguments();
  124. mocExe = args[4];
  125. cmakeExecutable = args[5];
  126. if (args.size() > 6) {
  127. if (args[6] == QLatin1String("--touch")) {
  128. doTouch = true;
  129. }
  130. }
  131. QByteArray line = dotFiles.readLine();
  132. dotFilesCheck(line == "MOC_COMPILE_DEFINITIONS:\n");
  133. line = dotFiles.readLine().trimmed();
  134. const QStringList &cdefList = QString::fromUtf8(line).split(';', QString::SkipEmptyParts);
  135. line = dotFiles.readLine();
  136. dotFilesCheck(line == "MOC_DEFINITIONS:\n");
  137. line = dotFiles.readLine().trimmed();
  138. if (!cdefList.isEmpty()) {
  139. foreach (const QString &def, cdefList) {
  140. Q_ASSERT(!def.isEmpty());
  141. mocDefinitions << QLatin1String("-D") + def;
  142. }
  143. } else {
  144. const QStringList &defList = QString::fromUtf8(line).split(' ', QString::SkipEmptyParts);
  145. foreach (const QString &def, defList) {
  146. Q_ASSERT(!def.isEmpty());
  147. if (def.startsWith(QLatin1String("-D"))) {
  148. mocDefinitions << def;
  149. }
  150. }
  151. }
  152. line = dotFiles.readLine();
  153. dotFilesCheck(line == "MOC_INCLUDES:\n");
  154. line = dotFiles.readLine().trimmed();
  155. const QStringList &incPaths = QString::fromUtf8(line).split(';', QString::SkipEmptyParts);
  156. foreach (const QString &path, incPaths) {
  157. Q_ASSERT(!path.isEmpty());
  158. mocIncludes << "-I" + path;
  159. }
  160. // on the Mac, add -F always, otherwise headers in the frameworks won't be found
  161. // is it necessary to do this only optionally ? Alex
  162. #ifdef Q_OS_MAC
  163. mocIncludes << "-F/Library/Frameworks";
  164. #endif
  165. line = dotFiles.readLine();
  166. dotFilesCheck(line == "CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE:\n");
  167. line = dotFiles.readLine();
  168. if (line == "ON\n") {
  169. line = dotFiles.readLine();
  170. dotFilesCheck(line == "CMAKE_BINARY_DIR:\n");
  171. const QString &binDir = QLatin1String("-I") + QString::fromUtf8(dotFiles.readLine().trimmed());
  172. line = dotFiles.readLine();
  173. dotFilesCheck(line == "CMAKE_SOURCE_DIR:\n");
  174. const QString &srcDir = QLatin1String("-I") + QString::fromUtf8(dotFiles.readLine().trimmed());
  175. QStringList sortedMocIncludes;
  176. QMutableListIterator<QString> it(mocIncludes);
  177. while (it.hasNext()) {
  178. if (it.next().startsWith(binDir)) {
  179. sortedMocIncludes << it.value();
  180. it.remove();
  181. }
  182. }
  183. it.toFront();
  184. while (it.hasNext()) {
  185. if (it.next().startsWith(srcDir)) {
  186. sortedMocIncludes << it.value();
  187. it.remove();
  188. }
  189. }
  190. sortedMocIncludes += mocIncludes;
  191. mocIncludes = sortedMocIncludes;
  192. }
  193. }
  194. bool AutoMoc::run()
  195. {
  196. const QStringList &args = QCoreApplication::arguments();
  197. Q_ASSERT(args.size() > 0);
  198. if (args.size() == 2) {
  199. if ((args[1]=="--help") || (args[1]=="-h")) {
  200. printUsage(args[0]);
  201. ::exit(0);
  202. }
  203. else if (args[1]=="--version") {
  204. printVersion();
  205. ::exit(0);
  206. }
  207. else {
  208. printUsage(args[0]);
  209. ::exit(EXIT_FAILURE);
  210. }
  211. }
  212. else if (args.size() < 5) {
  213. printUsage(args[0]);
  214. ::exit(EXIT_FAILURE);
  215. }
  216. QFile outfile(args[1]);
  217. const QFileInfo outfileInfo(outfile);
  218. QString srcdir(args[2]);
  219. if (!srcdir.endsWith('/')) {
  220. srcdir += '/';
  221. }
  222. builddir = args[3];
  223. if (!builddir.endsWith('/')) {
  224. builddir += '/';
  225. }
  226. generateAll = !outfile.exists();
  227. dotFiles.setFileName(args[1] + QLatin1String(".files"));
  228. dotFiles.open(QIODevice::ReadOnly | QIODevice::Text);
  229. const QByteArray &line = dotFiles.readLine();
  230. dotFilesCheck(line == "SOURCES:\n");
  231. const QStringList &sourceFiles = QString::fromUtf8(dotFiles.readLine().trimmed()).split(';', QString::SkipEmptyParts);
  232. // the program goes through all .cpp files to see which moc files are included. It is not really
  233. // interesting how the moc file is named, but what file the moc is created from. Once a moc is
  234. // included the same moc may not be included in the _automoc.cpp file anymore. OTOH if there's a
  235. // header containing Q_OBJECT where no corresponding moc file is included anywhere a
  236. // moc_<filename>.cpp file is created and included in the _automoc.cpp file.
  237. QHash<QString, QString> includedMocs; // key = moc source filepath, value = moc output filepath
  238. QHash<QString, QString> notIncludedMocs; // key = moc source filepath, value = moc output filename
  239. QRegExp mocIncludeRegExp(QLatin1String("[\n]\\s*#\\s*include\\s+[\"<](moc_[^ \">]+\\.cpp|[^ \">]+\\.moc)[\">]"));
  240. QRegExp qObjectRegExp(QLatin1String("[\n]\\s*Q_OBJECT\\b"));
  241. QStringList headerExtensions;
  242. #ifdef Q_OS_WIN
  243. // not case sensitive
  244. headerExtensions << ".h" << ".hpp" << ".hxx";
  245. #else
  246. headerExtensions << ".h" << ".hpp" << ".hxx" << ".H";
  247. #endif
  248. /* not safe: if a moc file is missing it's hard to get it generated if this check is "active"
  249. const QDateTime &lastRun = QFileInfo(dotFiles).lastModified();
  250. if (!generateAll) {
  251. bool dirty = false;
  252. foreach (const QString &absFilename, sourceFiles) {
  253. const QFileInfo sourceFileInfo(absFilename);
  254. if (sourceFileInfo.lastModified() >= lastRun) {
  255. dirty = true;
  256. break;
  257. }
  258. const QString &absPathBaseName = sourceFileInfo.absolutePath() + QLatin1Char('/') + sourceFileInfo.completeBaseName();
  259. foreach (const QString &ext, headerExtensions) {
  260. const QFileInfo header(absPathBaseName + ext);
  261. if (header.exists() && header.lastModified() >= lastRun) {
  262. dirty = true;
  263. break;
  264. }
  265. const QFileInfo pheader(absPathBaseName + QLatin1String("_p") + ext);
  266. if (pheader.exists() && pheader.lastModified() >= lastRun) {
  267. dirty = true;
  268. break;
  269. }
  270. }
  271. if (dirty) {
  272. break;
  273. }
  274. }
  275. if (!dirty) {
  276. return true;
  277. }
  278. }
  279. */
  280. foreach (const QString &absFilename, sourceFiles) {
  281. //qDebug() << absFilename;
  282. const QFileInfo sourceFileInfo(absFilename);
  283. if (absFilename.endsWith(".cpp") || absFilename.endsWith(".cc") ||
  284. absFilename.endsWith(".cxx") || absFilename.endsWith(".C")) {
  285. //qDebug() << "check .cpp file";
  286. QFile sourceFile(absFilename);
  287. sourceFile.open(QIODevice::ReadOnly);
  288. const QByteArray contents = sourceFile.readAll();
  289. if (contents.isEmpty()) {
  290. cerr << "automoc4: empty source file: " << absFilename << endl;
  291. continue;
  292. }
  293. const QString contentsString = QString::fromUtf8(contents);
  294. const QString absPath = sourceFileInfo.absolutePath() + '/';
  295. Q_ASSERT(absPath.endsWith('/'));
  296. int matchOffset = mocIncludeRegExp.indexIn(contentsString);
  297. if (matchOffset < 0) {
  298. // no moc #include, look whether we need to create a moc from the .h nevertheless
  299. //qDebug() << "no moc #include in the .cpp file";
  300. const QString basename = sourceFileInfo.completeBaseName();
  301. foreach (const QString &ext, headerExtensions) {
  302. const QString headername = absPath + basename + ext;
  303. if (QFile::exists(headername) && !includedMocs.contains(headername) &&
  304. !notIncludedMocs.contains(headername)) {
  305. const QString currentMoc = "moc_" + basename + ".cpp";
  306. QFile header(headername);
  307. header.open(QIODevice::ReadOnly);
  308. const QByteArray contents = header.readAll();
  309. if (qObjectRegExp.indexIn(QString::fromUtf8(contents)) >= 0) {
  310. //qDebug() << "header contains Q_OBJECT macro";
  311. notIncludedMocs.insert(headername, currentMoc);
  312. }
  313. break;
  314. }
  315. }
  316. foreach (const QString &ext, headerExtensions) {
  317. const QString privateHeaderName = absPath + basename + "_p" + ext;
  318. if (QFile::exists(privateHeaderName) && !includedMocs.contains(privateHeaderName) &&
  319. !notIncludedMocs.contains(privateHeaderName)) {
  320. const QString currentMoc = "moc_" + basename + "_p.cpp";
  321. QFile header(privateHeaderName);
  322. header.open(QIODevice::ReadOnly);
  323. const QByteArray contents = header.readAll();
  324. if (qObjectRegExp.indexIn(QString::fromUtf8(contents)) >= 0) {
  325. //qDebug() << "header contains Q_OBJECT macro";
  326. notIncludedMocs.insert(privateHeaderName, currentMoc);
  327. }
  328. break;
  329. }
  330. }
  331. } else {
  332. do { // call this for every moc include in the file
  333. const QString currentMoc = mocIncludeRegExp.cap(1);
  334. //qDebug() << "found moc include: " << currentMoc << " at offset " << matchOffset;
  335. QString basename = QFileInfo(currentMoc).completeBaseName();
  336. const bool moc_style = currentMoc.startsWith("moc_");
  337. if (moc_style || qObjectRegExp.indexIn(contentsString) < 0) {
  338. if (moc_style) {
  339. basename = basename.right(basename.length() - 4);
  340. }
  341. bool headerFound = false;
  342. foreach (const QString &ext, headerExtensions) {
  343. QString sourceFilePath = absPath + basename + ext;
  344. if (QFile::exists(sourceFilePath)) {
  345. headerFound = true;
  346. includedMocs.insert(sourceFilePath, currentMoc);
  347. notIncludedMocs.remove(sourceFilePath);
  348. break;
  349. }
  350. }
  351. if (!headerFound) {
  352. cerr << "automoc4: The file \"" << absFilename <<
  353. "\" includes the moc file \"" << currentMoc << "\", but \"" <<
  354. absPath + basename + "{" + headerExtensions.join(",") + "}" <<
  355. "\" do not exist." << endl;
  356. ::exit(EXIT_FAILURE);
  357. }
  358. } else {
  359. includedMocs.insert(absFilename, currentMoc);
  360. notIncludedMocs.remove(absFilename);
  361. }
  362. matchOffset = mocIncludeRegExp.indexIn(contentsString,
  363. matchOffset + currentMoc.length());
  364. } while(matchOffset >= 0);
  365. }
  366. } else if (absFilename.endsWith(".h") || absFilename.endsWith(".hpp") ||
  367. absFilename.endsWith(".hxx") || absFilename.endsWith(".H")) {
  368. if (!includedMocs.contains(absFilename) && !notIncludedMocs.contains(absFilename)) {
  369. // if this header is not getting processed yet and is explicitly mentioned for the
  370. // automoc the moc is run unconditionally on the header and the resulting file is
  371. // included in the _automoc.cpp file (unless there's a .cpp file later on that
  372. // includes the moc from this header)
  373. const QString currentMoc = "moc_" + sourceFileInfo.completeBaseName() + ".cpp";
  374. notIncludedMocs.insert(absFilename, currentMoc);
  375. }
  376. } else {
  377. if (verbose) {
  378. cout << "automoc4: ignoring file '" << absFilename << "' with unknown suffix" << endl;
  379. }
  380. }
  381. }
  382. // run moc on all the moc's that are #included in source files
  383. QHash<QString, QString>::ConstIterator end = includedMocs.constEnd();
  384. QHash<QString, QString>::ConstIterator it = includedMocs.constBegin();
  385. for (; it != end; ++it) {
  386. generateMoc(it.key(), it.value());
  387. }
  388. QByteArray automocSource;
  389. QTextStream outStream(&automocSource, QIODevice::WriteOnly);
  390. outStream << "/* This file is autogenerated, do not edit */\n";
  391. if (notIncludedMocs.isEmpty()) {
  392. outStream << "enum some_compilers { need_more_than_nothing };\n";
  393. } else {
  394. // run moc on the remaining headers and include them in the _automoc.cpp file
  395. end = notIncludedMocs.constEnd();
  396. it = notIncludedMocs.constBegin();
  397. for (; it != end; ++it) {
  398. if (generateMoc(it.key(), it.value())) {
  399. automocCppChanged = true;
  400. }
  401. outStream << "#include \"" << it.value() << "\"\n";
  402. }
  403. }
  404. // let all remaining moc processes finish
  405. waitForProcesses();
  406. if (failed) {
  407. // if any moc process failed we don't want to touch the _automoc.cpp file so that
  408. // automoc4 is rerun until the issue is fixed
  409. cerr << "returning failed.."<< endl;
  410. return false;
  411. }
  412. outStream.flush();
  413. if (!automocCppChanged) {
  414. // compare contents of the _automoc.cpp file
  415. outfile.open(QIODevice::ReadOnly | QIODevice::Text);
  416. const QByteArray oldContents = outfile.readAll();
  417. outfile.close();
  418. if (oldContents == automocSource) {
  419. // nothing changed: don't touch the _automoc.cpp file
  420. return true;
  421. }
  422. }
  423. // either the contents of the _automoc.cpp file or one of the mocs included by it have changed
  424. // source file that includes all remaining moc files (_automoc.cpp file)
  425. outfile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
  426. outfile.write(automocSource);
  427. outfile.close();
  428. // update the timestamp on the _automoc.cpp.files file to make sure we get called again
  429. dotFiles.close();
  430. if (doTouch && !touch(dotFiles.fileName())) {
  431. return false;
  432. }
  433. return true;
  434. }
  435. bool AutoMoc::touch(const QString &_filename)
  436. {
  437. // sleep for 1s in order to make the modification time greater than the modification time of
  438. // the files written before. Equal modification time is not good enough. Just using utime with
  439. // time(NULL) + 1 is also not a good solution as then make will complain about clock skew.
  440. #ifdef Q_OS_WIN
  441. Sleep(1000);
  442. _wutime(reinterpret_cast<const wchar_t *>(_filename.utf16()), 0);
  443. #else
  444. const QByteArray &filename = QFile::encodeName(_filename);
  445. const struct timespec sleepDuration = { 1, 0 };
  446. nanosleep(&sleepDuration, NULL);
  447. int err = utime(filename.constData(), NULL);
  448. if (err == -1) {
  449. err = errno;
  450. cerr << strerror(err) << "\n";
  451. return false;
  452. }
  453. #endif
  454. return true;
  455. }
  456. void AutoMoc::waitForProcesses()
  457. {
  458. while (!processes.isEmpty()) {
  459. Process proc = processes.dequeue();
  460. bool result = proc.qproc->waitForFinished(-1);
  461. //ignore errors from the cmake echo process
  462. if (!proc.mocFilePath.isEmpty()) {
  463. if (!result || proc.qproc->exitCode()) {
  464. cerr << "automoc4: process for " << proc.mocFilePath
  465. << " failed: " << proc.qproc->errorString() << endl;
  466. cerr << "pid to wait for: " << proc.qproc->pid() << endl;
  467. cerr << "processes in queue: " << processes.size() << endl;
  468. failed = true;
  469. QFile::remove(proc.mocFilePath);
  470. }
  471. }
  472. delete proc.qproc;
  473. }
  474. }
  475. bool AutoMoc::generateMoc(const QString &sourceFile, const QString &mocFileName)
  476. {
  477. //qDebug() << Q_FUNC_INFO << sourceFile << mocFileName;
  478. const QString mocFilePath = builddir + mocFileName;
  479. if (generateAll || QFileInfo(mocFilePath).lastModified() <= QFileInfo(sourceFile).lastModified()) {
  480. static bool initialized = false;
  481. if (!initialized) {
  482. initialized = true;
  483. lazyInit();
  484. }
  485. if (verbose) {
  486. echoColor("Generating " + mocFilePath + " from " + sourceFile);
  487. } else {
  488. echoColor("Generating " + mocFileName);
  489. }
  490. // we don't want too many child processes
  491. #ifdef Q_OS_FREEBSD
  492. static const int max_processes = 0;
  493. #else
  494. static const int max_processes = 10;
  495. #endif
  496. if (processes.size() > max_processes) {
  497. waitForProcesses();
  498. }
  499. QProcess *mocProc = new QProcess;
  500. mocProc->setProcessChannelMode(QProcess::ForwardedChannels);
  501. QStringList args(mocIncludes + mocDefinitions);
  502. #ifdef Q_OS_WIN
  503. args << "-DWIN32";
  504. #endif
  505. args << QLatin1String("-o") << mocFilePath << sourceFile;
  506. //qDebug() << "executing: " << mocExe << args;
  507. if (verbose) {
  508. cout << mocExe << " " << args.join(QLatin1String(" ")) << endl;
  509. }
  510. mocProc->start(mocExe, args, QIODevice::NotOpen);
  511. if (mocProc->waitForStarted()) {
  512. processes.enqueue(Process(mocProc, mocFilePath));
  513. return true;
  514. } else {
  515. cerr << "automoc4: process for " << mocFilePath << "failed to start: "
  516. << mocProc->errorString() << endl;
  517. failed = true;
  518. delete mocProc;
  519. }
  520. }
  521. return false;
  522. }