Added --verify-only option to qmlmin.
authorRoberto Raggi <roberto.raggi@nokia.com>
Tue, 13 Sep 2011 13:49:11 +0000 (15:49 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 19 Sep 2011 10:07:46 +0000 (12:07 +0200)
qmlmin has three different stages. In the first stage
it generates the QML/JS minified code. In the second
stage we verify that minified code is equivalent
to the original code and in the final stage we
produce the output. With --verify-only you can tell
qmlmin to quit after the verification step.

Note that this option is pretty much equivalent to
the unix command qmlmin file.qml -o /dev/null.

Change-Id: I91373bc1c1db8c35af2e301ad13d7b34fc384529
Reviewed-on: http://codereview.qt-project.org/4670
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>

tools/qmlmin/main.cpp

index ef848f6..5343a72 100644 (file)
@@ -411,6 +411,7 @@ static void usage(bool showHelp = false)
         std::cerr << " Removes comments and layout characters" << std::endl
                   << " The options are:" << std::endl
                   << "  -o<file>                write output to file rather than stdout" << std::endl
+                  << "  -v --verify-only        just run the verifier, no output" << std::endl
                   << "  -h                      display this output" << std::endl;
     }
 }
@@ -423,6 +424,7 @@ int main(int argc, char *argv[])
 
     QString fileName;
     QString outputFile;
+    bool verifyOnly = false;
 
     int index = 1;
     while (index < args.size()) {
@@ -432,6 +434,8 @@ int main(int argc, char *argv[])
         if (arg == QLatin1String("-h") || arg == QLatin1String("--help")) {
             usage(/*showHelp*/ true);
             return 0;
+        } else if (arg == QLatin1String("-v") || arg == QLatin1String("--verify-only")) {
+            verifyOnly = true;
         } else if (arg == QLatin1String("-o")) {
             if (next.isEmpty()) {
                 std::cerr << "qmlmin: argument to '-o' is missing" << std::endl;
@@ -500,18 +504,20 @@ int main(int argc, char *argv[])
         return EXIT_FAILURE;
     }
 
-    if (outputFile.isEmpty()) {
-        const QByteArray chars = minify.minifiedCode().toUtf8();
-        std::cout << chars.constData();
-    } else {
-        QFile file(outputFile);
-        if (! file.open(QFile::WriteOnly)) {
-            std::cerr << "qmlmin: cannot minify '" << qPrintable(fileName) << "' (permission denied)" << std::endl;
-            return EXIT_FAILURE;
-        }
+    if (! verifyOnly) {
+        if (outputFile.isEmpty()) {
+            const QByteArray chars = minify.minifiedCode().toUtf8();
+            std::cout << chars.constData();
+        } else {
+            QFile file(outputFile);
+            if (! file.open(QFile::WriteOnly)) {
+                std::cerr << "qmlmin: cannot minify '" << qPrintable(fileName) << "' (permission denied)" << std::endl;
+                return EXIT_FAILURE;
+            }
 
-        file.write(minify.minifiedCode().toUtf8());
-        file.close();
+            file.write(minify.minifiedCode().toUtf8());
+            file.close();
+        }
     }
 
     return 0;