qdoc: Clear outputdir in -prepare phase only
authorMartin Smith <martin.smith@digia.com>
Tue, 23 Oct 2012 13:11:06 +0000 (15:11 +0200)
committerMartin Smith <martin.smith@digia.com>
Tue, 23 Oct 2012 13:45:45 +0000 (15:45 +0200)
qdoc now clears the outputdir in the -prepare
phase but not in the -generate phase. It also
does not print error and warning messages in
the -prepare phase. It does print fatal errors
in the -prepare phase, of course, and the QML
parser prints syntax errors in the -prepare
phase, but all the qdoc errors and warnings
are only printed in the -generate phase.

Task number: QTBUG-27688

Change-Id: I9973a473260b4f79428f6b8e12a5ac35f3be15b4
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
src/tools/qdoc/generator.cpp
src/tools/qdoc/location.cpp

index c6db340..0384765 100644 (file)
@@ -1484,22 +1484,24 @@ void Generator::initialize(const Config &config)
 
         QDir dirInfo;
         if (dirInfo.exists(outDir_)) {
-            if (!Config::removeDirContents(outDir_))
-                config.lastLocation().error(tr("Cannot empty output directory '%1'").arg(outDir_));
+            if (!runGenerateOnly()) {
+                if (!Config::removeDirContents(outDir_))
+                    config.lastLocation().error(tr("Cannot empty output directory '%1'").arg(outDir_));
+            }
         }
         else {
             if (!dirInfo.mkpath(outDir_))
                 config.lastLocation().fatal(tr("Cannot create output directory '%1'").arg(outDir_));
         }
 
-        if (!dirInfo.mkdir(outDir_ + "/images"))
-            config.lastLocation().fatal(tr("Cannot create output directory '%1'").arg(outDir_ + "/images"));
-        if (!dirInfo.mkdir(outDir_ + "/images/used-in-examples"))
-            config.lastLocation().fatal(tr("Cannot create output directory '%1'").arg(outDir_ + "/images/used-in-examples"));
-        if (!dirInfo.mkdir(outDir_ + "/scripts"))
-            config.lastLocation().fatal(tr("Cannot create output directory '%1'").arg(outDir_ + "/scripts"));
-        if (!dirInfo.mkdir(outDir_ + "/style"))
-            config.lastLocation().fatal(tr("Cannot create output directory '%1'").arg(outDir_ + "/style"));
+        if (!dirInfo.exists(outDir_ + "/images") && !dirInfo.mkdir(outDir_ + "/images"))
+            config.lastLocation().fatal(tr("Cannot create images directory '%1'").arg(outDir_ + "/images"));
+        if (!dirInfo.exists(outDir_ + "/images/used-in-examples") && !dirInfo.mkdir(outDir_ + "/images/used-in-examples"))
+            config.lastLocation().fatal(tr("Cannot create images used in examples directory '%1'").arg(outDir_ + "/images/used-in-examples"));
+        if (!dirInfo.exists(outDir_ + "/scripts") && !dirInfo.mkdir(outDir_ + "/scripts"))
+            config.lastLocation().fatal(tr("Cannot create scripts directory '%1'").arg(outDir_ + "/scripts"));
+        if (!dirInfo.exists(outDir_ + "/style") && !dirInfo.mkdir(outDir_ + "/style"))
+            config.lastLocation().fatal(tr("Cannot create style directory '%1'").arg(outDir_ + "/style"));
     }
 
     imageFiles = config.getCleanPathList(CONFIG_IMAGES);
index ceb5709..8964633 100644 (file)
@@ -42,7 +42,7 @@
 #include <qdebug.h>
 #include "config.h"
 #include "location.h"
-
+#include "generator.h"
 #include <qdir.h>
 #include <qregexp.h>
 #include <stdlib.h>
@@ -260,25 +260,30 @@ QString Location::canonicalRelativePath(const QString &path) const
 
 /*!
   Writes \a message and \a detals to stderr as a formatted
-  warning message.
+  warning message. Does not write the message if qdoc is in
+  the Prepare phase.
  */
 void Location::warning(const QString& message, const QString& details) const
 {
-    emitMessage(Warning, message, details);
+    if (!Generator::runPrepareOnly())
+        emitMessage(Warning, message, details);
 }
 
 /*!
   Writes \a message and \a detals to stderr as a formatted
-  error message.
+  error message. Does not write the message if qdoc is in
+  the Prepare phase.
  */
 void Location::error(const QString& message, const QString& details) const
 {
-    emitMessage(Error, message, details);
+    if (!Generator::runPrepareOnly())
+        emitMessage(Error, message, details);
 }
 
 /*!
   Writes \a message and \a detals to stderr as a formatted
-  error message and then exits the program.
+  error message and then exits the program. qdoc prints fatal
+  errors in either phase (Prepare or Generate).
  */
 void Location::fatal(const QString& message, const QString& details) const
 {