summaryrefslogtreecommitdiff
path: root/src/qdoc/qdoccommandlineparser.cpp
diff options
context:
space:
mode:
authorPaul Wicking <paul.wicking@qt.io>2018-10-11 05:44:56 +0200
committerPaul Wicking <paul.wicking@qt.io>2018-10-12 14:01:22 +0000
commit2bc3b75c0a572bb36db666dbd8e24209d437e421 (patch)
treecd9ae3f51f0ccb41b9b585e065da79230dec7264 /src/qdoc/qdoccommandlineparser.cpp
parentc23d08e4315866110fc700fbfde3d3f02fb3344f (diff)
downloadqttools-2bc3b75c0a572bb36db666dbd8e24209d437e421.tar.gz
QDoc: Refactor command line parser class out of main.cpp
Move command line parser class out of main. Fix bug in QDocGlobals that caused include paths to break, by pushing one instead of two strings into a stringlist. Change-Id: I08b7eb02f1e3cf6e9ad33dc24322886ca2dc2fcd Reviewed-by: Martin Smith <martin.smith@qt.io>
Diffstat (limited to 'src/qdoc/qdoccommandlineparser.cpp')
-rw-r--r--src/qdoc/qdoccommandlineparser.cpp219
1 files changed, 219 insertions, 0 deletions
diff --git a/src/qdoc/qdoccommandlineparser.cpp b/src/qdoc/qdoccommandlineparser.cpp
new file mode 100644
index 000000000..4aa691fc9
--- /dev/null
+++ b/src/qdoc/qdoccommandlineparser.cpp
@@ -0,0 +1,219 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qdoccommandlineparser.h"
+
+#include <QtCore/qdebug.h>
+#include <QtCore/qfile.h>
+
+#include "config.h"
+#include "generator.h"
+#include "loggingcategory.h"
+
+QDocCommandLineParser::QDocCommandLineParser()
+ : QCommandLineParser(),
+ defineOption(QStringList() << QStringLiteral("D")),
+ dependsOption(QStringList() << QStringLiteral("depends")),
+ highlightingOption(QStringList() << QStringLiteral("highlighting")),
+ showInternalOption(QStringList() << QStringLiteral("showinternal")),
+ redirectDocumentationToDevNullOption(QStringList() << QStringLiteral("redirect-documentation-to-dev-null")),
+ noExamplesOption(QStringList() << QStringLiteral("no-examples")),
+ indexDirOption(QStringList() << QStringLiteral("indexdir")),
+ installDirOption(QStringList() << QStringLiteral("installdir")),
+ obsoleteLinksOption(QStringList() << QStringLiteral("obsoletelinks")),
+ outputDirOption(QStringList() << QStringLiteral("outputdir")),
+ outputFormatOption(QStringList() << QStringLiteral("outputformat")),
+ noLinkErrorsOption(QStringList() << QStringLiteral("no-link-errors")),
+ autoLinkErrorsOption(QStringList() << QStringLiteral("autolink-errors")),
+ debugOption(QStringList() << QStringLiteral("debug")),
+ prepareOption(QStringList() << QStringLiteral("prepare")),
+ generateOption(QStringList() << QStringLiteral("generate")),
+ logProgressOption(QStringList() << QStringLiteral("log-progress")),
+ singleExecOption(QStringList() << QStringLiteral("single-exec")),
+ writeQaPagesOption(QStringList() << QStringLiteral("write-qa-pages")),
+ includePathOption("I", "Add dir to the include path for header files.", "path"),
+ includePathSystemOption("isystem", "Add dir to the system include path for header files.", "path"),
+ frameworkOption("F", "Add macOS framework to the include path for header files.", "framework")
+{
+ setApplicationDescription(QCoreApplication::translate("qdoc", "Qt documentation generator"));
+ addHelpOption();
+ addVersionOption();
+
+ setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
+
+ addPositionalArgument("file1.qdocconf ...", QCoreApplication::translate("qdoc", "Input files"));
+
+ defineOption.setDescription(QCoreApplication::translate("qdoc", "Define the argument as a macro while parsing sources"));
+ defineOption.setValueName(QStringLiteral("macro[=def]"));
+ addOption(defineOption);
+
+ dependsOption.setDescription(QCoreApplication::translate("qdoc", "Specify dependent modules"));
+ dependsOption.setValueName(QStringLiteral("module"));
+ addOption(dependsOption);
+
+ highlightingOption.setDescription(QCoreApplication::translate("qdoc", "Turn on syntax highlighting (makes qdoc run slower)"));
+ addOption(highlightingOption);
+
+ showInternalOption.setDescription(QCoreApplication::translate("qdoc", "Include content marked internal"));
+ addOption(showInternalOption);
+
+ redirectDocumentationToDevNullOption.setDescription(QCoreApplication::translate("qdoc", "Save all documentation content to /dev/null. Useful if someone is interested in qdoc errors only."));
+ addOption(redirectDocumentationToDevNullOption);
+
+ noExamplesOption.setDescription(QCoreApplication::translate("qdoc", "Do not generate documentation for examples"));
+ addOption(noExamplesOption);
+
+ indexDirOption.setDescription(QCoreApplication::translate("qdoc", "Specify a directory where QDoc should search for index files to load"));
+ indexDirOption.setValueName(QStringLiteral("dir"));
+ addOption(indexDirOption);
+
+ installDirOption.setDescription(QCoreApplication::translate("qdoc", "Specify the directory where the output will be after running \"make install\""));
+ installDirOption.setValueName(QStringLiteral("dir"));
+ addOption(installDirOption);
+
+ obsoleteLinksOption.setDescription(QCoreApplication::translate("qdoc", "Report links from obsolete items to non-obsolete items"));
+ addOption(obsoleteLinksOption);
+
+ outputDirOption.setDescription(QCoreApplication::translate("qdoc", "Specify output directory, overrides setting in qdocconf file"));
+ outputDirOption.setValueName(QStringLiteral("dir"));
+ addOption(outputDirOption);
+
+ outputFormatOption.setDescription(QCoreApplication::translate("qdoc", "Specify output format, overrides setting in qdocconf file"));
+ outputFormatOption.setValueName(QStringLiteral("format"));
+ addOption(outputFormatOption);
+
+ noLinkErrorsOption.setDescription(QCoreApplication::translate("qdoc", "Do not print link errors (i.e. missing targets)"));
+ addOption(noLinkErrorsOption);
+
+ autoLinkErrorsOption.setDescription(QCoreApplication::translate("qdoc", "Show errors when automatic linking fails"));
+ addOption(autoLinkErrorsOption);
+
+ debugOption.setDescription(QCoreApplication::translate("qdoc", "Enable debug output"));
+ addOption(debugOption);
+
+ prepareOption.setDescription(QCoreApplication::translate("qdoc", "Run qdoc only to generate an index file, not the docs"));
+ addOption(prepareOption);
+
+ generateOption.setDescription(QCoreApplication::translate("qdoc", "Run qdoc to read the index files and generate the docs"));
+ addOption(generateOption);
+
+ logProgressOption.setDescription(QCoreApplication::translate("qdoc", "Log progress on stderr."));
+ addOption(logProgressOption);
+
+ singleExecOption.setDescription(QCoreApplication::translate("qdoc", "Run qdoc once over all the qdoc conf files."));
+ addOption(singleExecOption);
+
+ writeQaPagesOption.setDescription(QCoreApplication::translate("qdoc", "Write QA pages."));
+ addOption(writeQaPagesOption);
+
+ includePathOption.setFlags(QCommandLineOption::ShortOptionStyle);
+ addOption(includePathOption);
+
+ addOption(includePathSystemOption);
+
+ frameworkOption.setFlags(QCommandLineOption::ShortOptionStyle);
+ addOption(frameworkOption);
+}
+
+void QDocCommandLineParser::process(const QCoreApplication &app, QDocGlobals &qdocGlobals)
+{
+ QCommandLineParser::process(app);
+
+ qdocGlobals.addDefine(values(defineOption));
+ qdocGlobals.dependModules() += values(dependsOption);
+ qdocGlobals.enableHighlighting(isSet(highlightingOption));
+ qdocGlobals.setShowInternal(isSet(showInternalOption));
+ qdocGlobals.setSingleExec(isSet(singleExecOption));
+ qdocGlobals.setWriteQaPages(isSet(writeQaPagesOption));
+ qdocGlobals.setRedirectDocumentationToDevNull(isSet(redirectDocumentationToDevNullOption));
+ Config::generateExamples = !isSet(noExamplesOption);
+ foreach (const QString &indexDir, values(indexDirOption)) {
+ if (QFile::exists(indexDir))
+ qdocGlobals.appendToIndexDirs(indexDir);
+ else
+ qDebug() << "Cannot find index directory" << indexDir;
+ }
+ if (isSet(installDirOption))
+ Config::installDir = value(installDirOption);
+ qdocGlobals.setObsoleteLinks(isSet(obsoleteLinksOption));
+ if (isSet(outputDirOption))
+ Config::overrideOutputDir = value(outputDirOption);
+ foreach (const QString &format, values(outputFormatOption))
+ Config::overrideOutputFormats.insert(format);
+ qdocGlobals.setNoLinkErrors(isSet(noLinkErrorsOption) || qEnvironmentVariableIsSet("QDOC_NOLINKERRORS"));
+ qdocGlobals.setAutolinkErrors(isSet(autoLinkErrorsOption));
+ if (isSet(debugOption))
+ Generator::startDebugging(QString("command line"));
+ qCDebug(lcQdoc).noquote() << "Arguments :" << QCoreApplication::arguments();
+
+ if (isSet(prepareOption))
+ Generator::setQDocPass(Generator::Prepare);
+ if (isSet(generateOption))
+ Generator::setQDocPass(Generator::Generate);
+ if (isSet(singleExecOption)) {
+ Generator::setSingleExec();
+ if (isSet(indexDirOption))
+ qDebug() << "WARNING: -indexdir option ignored: Index files are not used in -single-exec mode.";
+ }
+ if (isSet(writeQaPagesOption))
+ Generator::setWriteQaPages();
+ if (isSet(logProgressOption))
+ Location::startLoggingProgress();
+
+ QDir currentDir = QDir::current();
+ const auto paths = values(includePathOption);
+ for (const auto &i : paths)
+ qdocGlobals.addIncludePath("-I", currentDir.absoluteFilePath(i));
+
+#ifdef QDOC_PASS_ISYSTEM
+ const auto paths2 = values(includePathSystemOption);
+ for (const auto &i : paths2)
+ qdocGlobals.addIncludePath("-isystem", currentDir.absoluteFilePath(i));
+#endif
+ const auto paths3 = values(frameworkOption);
+ for (const auto &i : paths3)
+ qdocGlobals.addIncludePath("-F", currentDir.absoluteFilePath(i));
+
+ /*
+ The default indent for code is 0.
+ The default value for false is 0.
+ The default supported file extensions are cpp, h, qdoc and qml.
+ The default language is c++.
+ The default output format is html.
+ The default tab size is 8.
+ And those are all the default values for configuration variables.
+ */
+ if (qdocGlobals.defaults().isEmpty()) {
+ qdocGlobals.defaults().insert(CONFIG_CODEINDENT, QLatin1String("0"));
+ qdocGlobals.defaults().insert(CONFIG_FALSEHOODS, QLatin1String("0"));
+ qdocGlobals.defaults().insert(CONFIG_FILEEXTENSIONS, QLatin1String("*.cpp *.h *.qdoc *.qml"));
+ qdocGlobals.defaults().insert(CONFIG_LANGUAGE, QLatin1String("Cpp"));
+ qdocGlobals.defaults().insert(CONFIG_OUTPUTFORMATS, QLatin1String("HTML"));
+ qdocGlobals.defaults().insert(CONFIG_TABSIZE, QLatin1String("8"));
+ }
+}