summaryrefslogtreecommitdiffstats
path: root/src/qdoc/qdoc/src/qdoc/qdoccommandlineparser.cpp
blob: 6586056a4569b2c2d7b9755568da1744a22deed2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "qdoccommandlineparser.h"

#include "utilities.h"

#include <QtCore/qdebug.h>
#include <QtCore/qfile.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")),
      outputDirOption(QStringList() << QStringLiteral("outputdir")),
      outputFormatOption(QStringList() << QStringLiteral("outputformat")),
      noLinkErrorsOption(QStringList() << QStringLiteral("no-link-errors")),
      autoLinkErrorsOption(QStringList() << QStringLiteral("autolink-errors")),
      debugOption(QStringList() << QStringLiteral("debug")),
      atomsDumpOption("atoms-dump"),
      prepareOption(QStringList() << QStringLiteral("prepare")),
      generateOption(QStringList() << QStringLiteral("generate")),
      logProgressOption(QStringList() << QStringLiteral("log-progress")),
      singleExecOption(QStringList() << QStringLiteral("single-exec")),
      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"),
      timestampsOption(QStringList() << QStringLiteral("timestamps")),
      useDocBookExtensions(QStringList() << QStringLiteral("docbook-extensions"))
{
    setApplicationDescription(QStringLiteral("Qt documentation generator"));
    addHelpOption();
    addVersionOption();

    setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);

    addPositionalArgument("file1.qdocconf ...", QStringLiteral("Input files"));

    defineOption.setDescription(
            QStringLiteral("Define the argument as a macro while parsing sources"));
    defineOption.setValueName(QStringLiteral("macro[=def]"));
    addOption(defineOption);

    dependsOption.setDescription(QStringLiteral("Specify dependent modules"));
    dependsOption.setValueName(QStringLiteral("module"));
    addOption(dependsOption);

    highlightingOption.setDescription(
            QStringLiteral("Turn on syntax highlighting (makes qdoc run slower)"));
    addOption(highlightingOption);

    showInternalOption.setDescription(QStringLiteral("Include content marked internal"));
    addOption(showInternalOption);

    redirectDocumentationToDevNullOption.setDescription(
            QStringLiteral("Save all documentation content to /dev/null. "
                           " Useful if someone is interested in qdoc errors only."));
    addOption(redirectDocumentationToDevNullOption);

    noExamplesOption.setDescription(QStringLiteral("Do not generate documentation for examples"));
    addOption(noExamplesOption);

    indexDirOption.setDescription(
            QStringLiteral("Specify a directory where QDoc should search for index files to load"));
    indexDirOption.setValueName(QStringLiteral("dir"));
    addOption(indexDirOption);

    installDirOption.setDescription(QStringLiteral(
            "Specify the directory where the output will be after running \"make install\""));
    installDirOption.setValueName(QStringLiteral("dir"));
    addOption(installDirOption);

    outputDirOption.setDescription(
            QStringLiteral("Specify output directory, overrides setting in qdocconf file"));
    outputDirOption.setValueName(QStringLiteral("dir"));
    addOption(outputDirOption);

    outputFormatOption.setDescription(
            QStringLiteral("Specify output format, overrides setting in qdocconf file"));
    outputFormatOption.setValueName(QStringLiteral("format"));
    addOption(outputFormatOption);

    noLinkErrorsOption.setDescription(
            QStringLiteral("Do not print link errors (i.e. missing targets)"));
    addOption(noLinkErrorsOption);

    autoLinkErrorsOption.setDescription(QStringLiteral("Show errors when automatic linking fails"));
    addOption(autoLinkErrorsOption);

    debugOption.setDescription(QStringLiteral("Enable debug output"));
    addOption(debugOption);

    atomsDumpOption.setDescription(QStringLiteral(
            "Shows a human-readable form of the intermediate result of parsing a block-comment."));
    addOption(atomsDumpOption);

    prepareOption.setDescription(
            QStringLiteral("Run qdoc only to generate an index file, not the docs"));
    addOption(prepareOption);

    generateOption.setDescription(
            QStringLiteral("Run qdoc to read the index files and generate the docs"));
    addOption(generateOption);

    logProgressOption.setDescription(QStringLiteral("Log progress on stderr."));
    addOption(logProgressOption);

    singleExecOption.setDescription(QStringLiteral("Run qdoc once over all the qdoc conf files."));
    addOption(singleExecOption);

    includePathOption.setFlags(QCommandLineOption::ShortOptionStyle);
    addOption(includePathOption);

    addOption(includePathSystemOption);

    frameworkOption.setFlags(QCommandLineOption::ShortOptionStyle);
    addOption(frameworkOption);

    timestampsOption.setDescription(QStringLiteral("Timestamp each qdoc log line."));
    addOption(timestampsOption);

    useDocBookExtensions.setDescription(
            QStringLiteral("Use the DocBook Library extensions for metadata."));
    addOption(useDocBookExtensions);
}

/*!
 * \internal
 *
 * Create a list of arguments from the command line and/or file(s).
 * This lets QDoc accept arguments contained in a file provided as a
 * command-line argument prepended by '@'.
 */
static QStringList argumentsFromCommandLineAndFile(const QStringList &arguments)
{
    QStringList allArguments;
    allArguments.reserve(arguments.size());
    for (const QString &argument : arguments) {
        // "@file" doesn't start with a '-' so we can't use QCommandLineParser for it
        if (argument.startsWith(QLatin1Char('@'))) {
            QString optionsFile = argument;
            optionsFile.remove(0, 1);
            if (optionsFile.isEmpty())
                qFatal("The @ option requires an input file");
            QFile f(optionsFile);
            if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
                qFatal("Cannot open options file specified with @: %ls",
                       qUtf16Printable(optionsFile));
            while (!f.atEnd()) {
                QString line = QString::fromLocal8Bit(f.readLine().trimmed());
                if (!line.isEmpty())
                    allArguments << line;
            }
        } else {
            allArguments << argument;
        }
    }
    return allArguments;
}

void QDocCommandLineParser::process(const QStringList &arguments)
{
    auto allArguments = argumentsFromCommandLineAndFile(arguments);
    QCommandLineParser::process(allArguments);

    if (isSet(singleExecOption) && isSet(indexDirOption))
        qCWarning(lcQdoc) << "Warning: -indexdir option ignored: Index files are not used in single-exec mode.";
}