qdoc: Don't load index in -prepare phase

qdoc was loading index files during the -prepare
phase, which it shouldn't do. The index files it
was loading were from modules other than the one
qdoc was running on. They had not been deleted
because qdoc only clears the output directory of
the module it is running on.

Also added a static function to the Location class
to print information messages on standard error.
This is useful to see what qdoc is doing and when
it is doing it because these log messages are
interleaved in the qdoc error messages. More of
these log messages will be added as needed.

Also removed some unneeded qDebug() stuff in
the code that processes the dependencies from
the qdocconf file.

Task number: QTBUG-27707

Change-Id: I1eec8d6ec89ff040969c2a1f62f21f551f347e05
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
This commit is contained in:
Martin Smith 2012-10-25 12:44:16 +02:00
parent 600f2397b8
commit 34d2a7e6b6
4 changed files with 148 additions and 118 deletions

View File

@ -335,6 +335,15 @@ void Location::information(const QString& message)
fflush(stdout);
}
/*!
Prints \a message to \c stderr followed by a \c{'\n'}.
*/
void Location::logToStdErr(const QString& message)
{
fprintf(stderr, "%s\n", message.toLatin1().data());
fflush(stderr);
}
/*!
Report a program bug, including the \a hint.
*/

View File

@ -96,6 +96,7 @@ public:
static void terminate();
static void information(const QString& message);
static void internalError(const QString& hint);
static void logToStdErr(const QString& message);
private:
enum MessageType { Warning, Error };

View File

@ -101,6 +101,9 @@ static bool obsoleteLinks = false;
static QStringList defines;
static QStringList dependModules;
static QStringList indexDirs;
static QString currentDir;
static QString prevCurrentDir;
static QString documentationPath;
/*!
Print the help message to \c stdout.
@ -118,7 +121,7 @@ static void printHelp()
" -highlighting "
"Turn on syntax highlighting (makes qdoc run slower)\n"
" -indexdir "
"Specify a directory where QDoc should search for indices to link to\n"
"Specify a directory where QDoc should search for index files to load\n"
" -installdir "
"Specify the directory where the output will be after running \"make install\"\n"
" -no-examples "
@ -150,116 +153,9 @@ static void printVersion()
Location::information(s);
}
/*!
Processes the qdoc config file \a fileName. This is the
controller for all of qdoc.
*/
static void processQdocconfFile(const QString &fileName)
static void loadIndexFiles(Config& config)
{
#ifndef QT_NO_TRANSLATION
QList<QTranslator *> translators;
#endif
/*
The Config instance represents the configuration data for qdoc.
All the other classes are initialized with the config. Here we
initialize the configuration with some default values.
*/
Config config(tr("qdoc"));
int i = 0;
while (defaults[i].key) {
config.setStringList(defaults[i].key,
QStringList() << defaults[i].value);
++i;
}
config.setStringList(CONFIG_SYNTAXHIGHLIGHTING, QStringList(highlighting ? "true" : "false"));
config.setStringList(CONFIG_SHOWINTERNAL, QStringList(showInternal ? "true" : "false"));
config.setStringList(CONFIG_NOLINKERRORS, QStringList(noLinkErrors ? "true" : "false"));
config.setStringList(CONFIG_OBSOLETELINKS, QStringList(obsoleteLinks ? "true" : "false"));
QString documentationPath = QLibraryInfo::rawLocation(QLibraryInfo::DocumentationPath,
QLibraryInfo::EffectivePaths);
// Set a few environment variables that can be used from the qdocconf file
qputenv("QT_INSTALL_DOCS", documentationPath.toLatin1());
/*
With the default configuration values in place, load
the qdoc configuration file. Note that the configuration
file may include other configuration files.
The Location class keeps track of the current location
in the file being processed, mainly for error reporting
purposes.
*/
Location::initialize(config);
config.load(fileName);
/*
Add the defines to the configuration variables.
*/
QStringList defs = defines + config.getStringList(CONFIG_DEFINES);
config.setStringList(CONFIG_DEFINES,defs);
Location::terminate();
QString prevCurrentDir = QDir::currentPath();
QString dir = QFileInfo(fileName).path();
if (!dir.isEmpty())
QDir::setCurrent(dir);
/*
Initialize all the classes and data structures with the
qdoc configuration.
*/
Location::initialize(config);
Tokenizer::initialize(config);
Doc::initialize(config);
CodeMarker::initialize(config);
CodeParser::initialize(config);
Generator::initialize(config);
#ifndef QT_NO_TRANSLATION
/*
Load the language translators, if the configuration specifies any.
*/
QStringList fileNames = config.getStringList(CONFIG_TRANSLATORS);
QStringList::Iterator fn = fileNames.constBegin();
while (fn != fileNames.constEnd()) {
QTranslator *translator = new QTranslator(0);
if (!translator->load(*fn))
config.lastLocation().error(tr("Cannot load translator '%1'")
.arg(*fn));
QCoreApplication::instance()->installTranslator(translator);
translators.append(translator);
++fn;
}
#endif
//QSet<QString> outputLanguages = config.getStringSet(CONFIG_OUTPUTLANGUAGES);
/*
Get the source language (Cpp) from the configuration
and the location in the configuration file where the
source language was set.
*/
QString lang = config.getString(CONFIG_LANGUAGE);
Location langLocation = config.lastLocation();
/*
Initialize the qdoc database, where all the parsed source files
will be stored. The database includes a tree of nodes, which gets
built as the source files are parsed. The documentation output is
generated by traversing that tree.
*/
QDocDatabase* qdb = QDocDatabase::qdocDB();
qdb->setVersion(config.getString(CONFIG_VERSION));
/*
By default, the only output format is HTML.
*/
QSet<QString> outputFormats = config.getOutputFormats();
Location outputFormatsLocation = config.lastLocation();
/*
Read some XML indexes containing definitions from other documentation sets.
*/
@ -276,14 +172,14 @@ static void processQdocconfFile(const QString &fileName)
if (indexDirs.size() > 0) {
for (int i = 0; i < indexDirs.size(); i++) {
if (indexDirs[i].startsWith("..")) {
const QString prefix(QDir(dir).relativeFilePath(prevCurrentDir));
const QString prefix(QDir(currentDir).relativeFilePath(prevCurrentDir));
if (!prefix.isEmpty())
indexDirs[i].prepend(prefix + QLatin1Char('/'));
}
}
/*
Add all subdirectories of the indexdirs as dependModules when an asterisk is used in
the 'depends' list.
Add all subdirectories of the indexdirs as dependModules,
when an asterisk is used in the 'depends' list.
*/
if (dependModules.contains("*")) {
dependModules.removeOne("*");
@ -326,20 +222,137 @@ static void processQdocconfFile(const QString &fileName)
else if (foundIndices.size() == 1) {
indexToAdd = foundIndices[0].absoluteFilePath();
}
else {
qDebug() << "No indices for" << dependModules[i] <<
"could be found in the specified index directories.";
}
if (!indexToAdd.isEmpty() && !indexFiles.contains(indexToAdd))
indexFiles << indexToAdd;
}
}
else {
qDebug() << "Dependant modules specified, but no index directories or install directory were set."
qDebug() << "Dependant modules specified, but no index directories or "
<< "install directory were set."
<< "There will probably be errors for missing links.";
}
}
qdb->readIndexes(indexFiles);
}
/*!
Processes the qdoc config file \a fileName. This is the
controller for all of qdoc.
*/
static void processQdocconfFile(const QString &fileName)
{
#ifndef QT_NO_TRANSLATION
QList<QTranslator *> translators;
#endif
/*
The Config instance represents the configuration data for qdoc.
All the other classes are initialized with the config. Here we
initialize the configuration with some default values.
*/
Config config(tr("qdoc"));
int i = 0;
while (defaults[i].key) {
config.setStringList(defaults[i].key, QStringList() << defaults[i].value);
++i;
}
config.setStringList(CONFIG_SYNTAXHIGHLIGHTING, QStringList(highlighting ? "true" : "false"));
config.setStringList(CONFIG_SHOWINTERNAL, QStringList(showInternal ? "true" : "false"));
config.setStringList(CONFIG_NOLINKERRORS, QStringList(noLinkErrors ? "true" : "false"));
config.setStringList(CONFIG_OBSOLETELINKS, QStringList(obsoleteLinks ? "true" : "false"));
documentationPath = QLibraryInfo::rawLocation(QLibraryInfo::DocumentationPath,
QLibraryInfo::EffectivePaths);
// Set a few environment variables that can be used from the qdocconf file
qputenv("QT_INSTALL_DOCS", documentationPath.toLatin1());
/*
With the default configuration values in place, load
the qdoc configuration file. Note that the configuration
file may include other configuration files.
The Location class keeps track of the current location
in the file being processed, mainly for error reporting
purposes.
*/
Location::initialize(config);
config.load(fileName);
/*
Add the defines to the configuration variables.
*/
QStringList defs = defines + config.getStringList(CONFIG_DEFINES);
config.setStringList(CONFIG_DEFINES,defs);
Location::terminate();
prevCurrentDir = QDir::currentPath();
currentDir = QFileInfo(fileName).path();
if (!currentDir.isEmpty())
QDir::setCurrent(currentDir);
QString phase;
if (Generator::runPrepareOnly())
phase = "in -prepare mode ";
else if (Generator::runGenerateOnly())
phase = "in -generate mode ";
QString msg = "Running qdoc " + phase + "for " + config.getString(CONFIG_PROJECT);
Location::logToStdErr(msg);
/*
Initialize all the classes and data structures with the
qdoc configuration.
*/
Location::initialize(config);
Tokenizer::initialize(config);
Doc::initialize(config);
CodeMarker::initialize(config);
CodeParser::initialize(config);
Generator::initialize(config);
#ifndef QT_NO_TRANSLATION
/*
Load the language translators, if the configuration specifies any.
*/
QStringList fileNames = config.getStringList(CONFIG_TRANSLATORS);
QStringList::Iterator fn = fileNames.constBegin();
while (fn != fileNames.constEnd()) {
QTranslator *translator = new QTranslator(0);
if (!translator->load(*fn))
config.lastLocation().error(tr("Cannot load translator '%1'").arg(*fn));
QCoreApplication::instance()->installTranslator(translator);
translators.append(translator);
++fn;
}
#endif
//QSet<QString> outputLanguages = config.getStringSet(CONFIG_OUTPUTLANGUAGES);
/*
Get the source language (Cpp) from the configuration
and the location in the configuration file where the
source language was set.
*/
QString lang = config.getString(CONFIG_LANGUAGE);
Location langLocation = config.lastLocation();
/*
Initialize the qdoc database, where all the parsed source files
will be stored. The database includes a tree of nodes, which gets
built as the source files are parsed. The documentation output is
generated by traversing that tree.
*/
QDocDatabase* qdb = QDocDatabase::qdocDB();
qdb->setVersion(config.getString(CONFIG_VERSION));
/*
By default, the only output format is HTML.
*/
QSet<QString> outputFormats = config.getOutputFormats();
Location outputFormatsLocation = config.lastLocation();
if (!Generator::runPrepareOnly())
loadIndexFiles(config);
QSet<QString> excludedDirs;
QSet<QString> excludedFiles;

View File

@ -48,6 +48,7 @@
#include "location.h"
#include "atom.h"
#include "generator.h"
#include <qdebug.h>
//include "doc.h"
//include "htmlgenerator.h"
@ -109,8 +110,11 @@ void QDocIndexFiles::destroyQDocIndexFiles()
*/
void QDocIndexFiles::readIndexes(const QStringList& indexFiles)
{
foreach (const QString& indexFile, indexFiles)
foreach (const QString& indexFile, indexFiles) {
QString msg = " Loading index file: " + indexFile;
Location::logToStdErr(msg);
readIndexFile(indexFile);
}
}
/*!
@ -1048,6 +1052,9 @@ void QDocIndexFiles::generateIndex(const QString& fileName,
if (!file.open(QFile::WriteOnly | QFile::Text))
return;
QString msg = " Writing index file: " + fileName;
Location::logToStdErr(msg);
gen_ = g;
QXmlStreamWriter writer(&file);
writer.setAutoFormatting(true);