diff --git a/src/tools/qdoc/location.cpp b/src/tools/qdoc/location.cpp index 8964633125..48e5d6153c 100644 --- a/src/tools/qdoc/location.cpp +++ b/src/tools/qdoc/location.cpp @@ -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. */ diff --git a/src/tools/qdoc/location.h b/src/tools/qdoc/location.h index d2c9487968..71492e619f 100644 --- a/src/tools/qdoc/location.h +++ b/src/tools/qdoc/location.h @@ -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 }; diff --git a/src/tools/qdoc/main.cpp b/src/tools/qdoc/main.cpp index 5fbc01f1f0..d46580bbea 100644 --- a/src/tools/qdoc/main.cpp +++ b/src/tools/qdoc/main.cpp @@ -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 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 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 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 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 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 outputFormats = config.getOutputFormats(); + Location outputFormatsLocation = config.lastLocation(); + + if (!Generator::runPrepareOnly()) + loadIndexFiles(config); QSet excludedDirs; QSet excludedFiles; diff --git a/src/tools/qdoc/qdocindexfiles.cpp b/src/tools/qdoc/qdocindexfiles.cpp index d68fe0e6fa..6d697c61b0 100644 --- a/src/tools/qdoc/qdocindexfiles.cpp +++ b/src/tools/qdoc/qdocindexfiles.cpp @@ -48,6 +48,7 @@ #include "location.h" #include "atom.h" #include "generator.h" +#include //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);